6
$\begingroup$

I've generated a table of the form

tupleListImport = {{theta_1, phi_1, value_1},{theta_2, phi_2, value_2},{theta_3, phi_3, value_3},.....,{theta_n, phi_n, value_n}},

where:

theta is a polar angle (in degrees) and ranges from 0 to 180 degrees, and

phi is an azimuthal angle (also in degrees) and ranges from 0 to 360 degrees, and

value is a number ranging between 0 and 1.

For your convenience, you can find the Table evaluated in steps of 10 degree in both the polar and azimuthal angles on my one drive tupleListImport.

When I plot tupleListImport using ListPlot3D and ListContourPlot, that is,

p1 = ListPlot3D[tupleListImport, ColorFunction -> "SunsetColors", 
   AxesLabel -> {"\!\(\*SubscriptBox[\(\[Theta]\), \(2\)]\)", 
     "\!\(\*SubscriptBox[\(\[Phi]\), \(2\)]\)", 
     "con01"}, {PlotStyle -> Thick, AxesStyle -> Thick}, 
   LabelStyle -> Directive[Bold, White, Medium], ImageSize -> 400];

p2 = ListContourPlot[tupleListImport, ColorFunction -> "SunsetColors",
    FrameLabel -> {Style["\!\(\*SubscriptBox[\(\[Theta]\), \(2\)]\)", 
      Medium, Bold, White], 
     Style["\!\(\*SubscriptBox[\(\[Phi]\), \(2\)]\)", Medium, Bold, 
      White]}, {PlotStyle -> Thick, AxesStyle -> Thick}, 
   LabelStyle -> Directive[Bold, White, Medium], ImageSize -> 400, 
   InterpolationOrder -> 3, ContourLabels -> All, 
   ContourStyle -> {Magenta, Dashed}, PlotLegends -> Automatic];

the plots (when evaluated in 1 degree steps) look like

enter image description here

What I would like to do is map the contour plots on a unit sphere using the same colour function, i.e., (ColorFunction -> "SunsetColors") so that the final plot looks something like this that I found on the internet.

enter image description here

I have made an attempt to generate this plot using the following code

(*Extracting individual lists of angles and values*)
thetaListDegrees = tupleListImport[[All, 1]];
phiListDegrees = tupleListImport[[All, 2]];
conList = tupleListImport[[All, 3]];

(*Convert degrees to radians*)
thetaList = thetaListDegrees Degree;
phiList = phiListDegrees Degree;

(*Define a function for the color based on con*)
colorFunction[con_] := ColorData["SunsetColors"][con]

(*Mapping the values to the sphere*)
points = N[
   Table[{Sin[theta] Cos[phi], Sin[theta] Sin[phi], 
     Cos[theta]}, {theta, thetaList}, {phi, phiList}], 4];

(*Flatten the points and conList for VertexColors*)
flattenedPoints = Flatten[Most /@ points, 1];
flattenedConList = Flatten[conList];

(*Create a SphericalPlot3D with colored points on the sphere*)
SphericalPlot3D[1, {theta, 0, Pi}, {phi, 0, 2 Pi}, 
 MeshFunctions -> {#5 &}, 
 MeshStyle -> Directive[PointSize[Small], AbsolutePointSize[8]], 
 MeshShading -> colorFunction /@ flattenedConList, PlotStyle -> None, 
 Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1}, 
 ViewPoint -> {2, 2, 1}, ImageSize -> Large]

which generates (using steps of 10 degrees) a surface plot that looks like this

But this surface plot does not look consistent with the variation in colour compared to the contour plot above.

Also, the code freezes up if I attempt to generate a contour surface plot if I use 1 degree steps. I have run out of ideas on how to fix my code so that I accurately map the contours plot generated using ListContourPlot onto the surface of a unit sphere and how I can fix my code so that I can map any table with arbitrary polar or azimuthal angle step sizes. Any suggestion would be most welcome.

Thank you if you have gotten this far. :)

$\endgroup$
5
  • $\begingroup$ What is the function you used to generate tupleListImport? $\endgroup$ Commented Nov 13, 2023 at 21:10
  • $\begingroup$ Is it some kind of orbital? $\endgroup$ Commented Nov 13, 2023 at 22:03
  • $\begingroup$ It's a test function that I'm using to work out how to generate the surface contour map on a unit sphere. $\endgroup$ Commented Nov 13, 2023 at 22:14
  • $\begingroup$ There is function SliceContourPlot3D that can do that, but you would need the function to be defined in cartesian coordinates. Can you define your function in the form f(x,y,z)=0 instead of spherical coordinates? $\endgroup$ Commented Nov 13, 2023 at 22:18
  • $\begingroup$ I can't think of a way to do it like that. I think it has to be done using tupleListImport some how. $\endgroup$ Commented Nov 13, 2023 at 22:21

1 Answer 1

11
$\begingroup$

data in my code is yours tupleListImport.

It seems that the plots match to each other.

data={{0,0,1.000},{0,10,0.9397},{0,20,0.7660},{0,30,0.5000},{0,40,0.1736},{0,50,0.1736},{0,60,0.5000},{0,70,0.7660},{0,80,0.9397},{0,90,1.000},{0,100,0.9397},{0,110,0.7660},{0,120,0.5000},{0,130,0.1736},{0,140,0.1736},{0,150,0.5000},{0,160,0.7660},{0,170,0.9397},{0,180,1.000},{0,190,0.9397},{0,200,0.7660},{0,210,0.5000},{0,220,0.1736},{0,230,0.1736},{0,240,0.5000},{0,250,0.7660},{0,260,0.9397},{0,270,1.000},{0,280,0.9397},{0,290,0.7660},{0,300,0.5000},{0,310,0.1736},{0,320,0.1736},{0,330,0.5000},{0,340,0.7660},{0,350,0.9397},{0,360,1.000},{10,0,0.9998},{10,10,0.9395},{10,20,0.7659},{10,30,0.4999},{10,40,0.1736},{10,50,0.1736},{10,60,0.4999},{10,70,0.7659},{10,80,0.9395},{10,90,0.9998},{10,100,0.9395},{10,110,0.7659},{10,120,0.4999},{10,130,0.1736},{10,140,0.1736},{10,150,0.4999},{10,160,0.7659},{10,170,0.9395},{10,180,0.9998},{10,190,0.9395},{10,200,0.7659},{10,210,0.4999},{10,220,0.1736},{10,230,0.1736},{10,240,0.4999},{10,250,0.7659},{10,260,0.9395},{10,270,0.9998},{10,280,0.9395},{10,290,0.7659},{10,300,0.4999},{10,310,0.1736},{10,320,0.1736},{10,330,0.4999},{10,340,0.7659},{10,350,0.9395},{10,360,0.9998},{20,0,0.9962},{20,10,0.9361},{20,20,0.7631},{20,30,0.4981},{20,40,0.1729},{20,50,0.1729},{20,60,0.4981},{20,70,0.7631},{20,80,0.9361},{20,90,0.9962},{20,100,0.9361},{20,110,0.7631},{20,120,0.4981},{20,130,0.1729},{20,140,0.1729},{20,150,0.4981},{20,160,0.7631},{20,170,0.9361},{20,180,0.9962},{20,190,0.9361},{20,200,0.7631},{20,210,0.4981},{20,220,0.1729},{20,230,0.1729},{20,240,0.4981},{20,250,0.7631},{20,260,0.9361},{20,270,0.9962},{20,280,0.9361},{20,290,0.7631},{20,300,0.4981},{20,310,0.1729},{20,320,0.1729},{20,330,0.4981},{20,340,0.7631},{20,350,0.9361},{20,360,0.9962},{30,0,0.9803},{30,10,0.9211},{30,20,0.7508},{30,30,0.4898},{30,40,0.1697},{30,50,0.1697},{30,60,0.4898},{30,70,0.7508},{30,80,0.9211},{30,90,0.9803},{30,100,0.9211},{30,110,0.7508},{30,120,0.4898},{30,130,0.1697},{30,140,0.1697},{30,150,0.4898},{30,160,0.7508},{30,170,0.9211},{30,180,0.9803},{30,190,0.9211},{30,200,0.7508},{30,210,0.4898},{30,220,0.1697},{30,230,0.1697},{30,240,0.4898},{30,250,0.7508},{30,260,0.9211},{30,270,0.9803},{30,280,0.9211},{30,290,0.7508},{30,300,0.4898},{30,310,0.1697},{30,320,0.1697},{30,330,0.4898},{30,340,0.7508},{30,350,0.9211},{30,360,0.9803},{40,0,0.9361},{40,10,0.8794},{40,20,0.7163},{40,30,0.4664},{40,40,0.1598},{40,50,0.1598},{40,60,0.4664},{40,70,0.7163},{40,80,0.8794},{40,90,0.9361},{40,100,0.8794},{40,110,0.7163},{40,120,0.4664},{40,130,0.1598},{40,140,0.1598},{40,150,0.4664},{40,160,0.7163},{40,170,0.8794},{40,180,0.9361},{40,190,0.8794},{40,200,0.7163},{40,210,0.4664},{40,220,0.1598},{40,230,0.1598},{40,240,0.4664},{40,250,0.7163},{40,260,0.8794},{40,270,0.9361},{40,280,0.8794},{40,290,0.7163},{40,300,0.4664},{40,310,0.1598},{40,320,0.1598},{40,330,0.4664},{40,340,0.7163},{40,350,0.8794},{40,360,0.9361},{50,0,0.8418},{50,10,0.7903},{50,20,0.6421},{50,30,0.4149},{50,40,0.1361},{50,50,0.1361},{50,60,0.4149},{50,70,0.6421},{50,80,0.7903},{50,90,0.8418},{50,100,0.7903},{50,110,0.6421},{50,120,0.4149},{50,130,0.1361},{50,140,0.1361},{50,150,0.4149},{50,160,0.6421},{50,170,0.7903},{50,180,0.8418},{50,190,0.7903},{50,200,0.6421},{50,210,0.4149},{50,220,0.1361},{50,230,0.1361},{50,240,0.4149},{50,250,0.6421},{50,260,0.7903},{50,270,0.8418},{50,280,0.7903},{50,290,0.6421},{50,300,0.4149},{50,310,0.1361},{50,320,0.1361},{50,330,0.4149},{50,340,0.6421},{50,350,0.7903},{50,360,0.8418},{60,0,0.6765},{60,10,0.6337},{60,20,0.5106},{60,30,0.3219},{60,40,0.09022},{60,50,0.09022},{60,60,0.3219},{60,70,0.5106},{60,80,0.6337},{60,90,0.6765},{60,100,0.6337},{60,110,0.5106},{60,120,0.3219},{60,130,0.09022},{60,140,0.09022},{60,150,0.3219},{60,160,0.5106},{60,170,0.6337},{60,180,0.6765},{60,190,0.6337},{60,200,0.5106},{60,210,0.3219},{60,220,0.09022},{60,230,0.09022},{60,240,0.3219},{60,250,0.5106},{60,260,0.6337},{60,270,0.6765},{60,280,0.6337},{60,290,0.5106},{60,300,0.3219},{60,310,0.09022},{60,320,0.09022},{60,330,0.3219},{60,340,0.5106},{60,350,0.6337},{60,360,0.6765},{70,0,0.4340},{70,10,0.4037},{70,20,0.3162},{70,30,0.1820},{70,40,0.01681},{70,50,0.01681},{70,60,0.1820},{70,70,0.3162},{70,80,0.4037},{70,90,0.4340},{70,100,0.4037},{70,110,0.3162},{70,120,0.1820},{70,130,0.01681},{70,140,0.01681},{70,150,0.1820},{70,160,0.3162},{70,170,0.4037},{70,180,0.4340},{70,190,0.4037},{70,200,0.3162},{70,210,0.1820},{70,220,0.01681},{70,230,0.01681},{70,240,0.1820},{70,250,0.3162},{70,260,0.4037},{70,270,0.4340},{70,280,0.4037},{70,290,0.3162},{70,300,0.1820},{70,310,0.01681},{70,320,0.01681},{70,330,0.1820},{70,340,0.3162},{70,350,0.4037},{70,360,0.4340},{80,0,0.1373},{80,10,0.1218},{80,20,0.07700},{80,30,0.008029},{80,40,0},{80,50,0},{80,60,0.008029},{80,70,0.07700},{80,80,0.1218},{80,90,0.1373},{80,100,0.1218},{80,110,0.07700},{80,120,0.008029},{80,130,0},{80,140,0},{80,150,0.008029},{80,160,0.07700},{80,170,0.1218},{80,180,0.1373},{80,190,0.1218},{80,200,0.07700},{80,210,0.008029},{80,220,0},{80,230,0},{80,240,0.008029},{80,250,0.07700},{80,260,0.1218},{80,270,0.1373},{80,280,0.1218},{80,290,0.07700},{80,300,0.008029},{80,310,0},{80,320,0},{80,330,0.008029},{80,340,0.07700},{80,350,0.1218},{80,360,0.1373},{90,0,0},{90,10,0},{90,20,0},{90,30,0},{90,40,0},{90,50,0},{90,60,0},{90,70,0},{90,80,0},{90,90,0},{90,100,0},{90,110,0},{90,120,0},{90,130,0},{90,140,0},{90,150,0},{90,160,0},{90,170,0},{90,180,0},{90,190,0},{90,200,0},{90,210,0},{90,220,0},{90,230,0},{90,240,0},{90,250,0},{90,260,0},{90,270,0},{90,280,0},{90,290,0},{90,300,0},{90,310,0},{90,320,0},{90,330,0},{90,340,0},{90,350,0},{90,360,0},{100,0,0.05137},{100,10,0.03793},{100,20,0},{100,30,0},{100,40,0},{100,50,0},{100,60,0},{100,70,0},{100,80,0.03793},{100,90,0.05137},{100,100,0.03793},{100,110,0},{100,120,0},{100,130,0},{100,140,0},{100,150,0},{100,160,0},{100,170,0.03793},{100,180,0.05137},{100,190,0.03793},{100,200,0},{100,210,0},{100,220,0},{100,230,0},{100,240,0},{100,250,0},{100,260,0.03793},{100,270,0.05137},{100,280,0.03793},{100,290,0},{100,300,0},{100,310,0},{100,320,0},{100,330,0},{100,340,0},{100,350,0.03793},{100,360,0.05137},{110,0,0.2286},{110,10,0.2059},{110,20,0.1404},{110,30,0.03968},{110,40,0},{110,50,0},{110,60,0.03968},{110,70,0.1404},{110,80,0.2059},{110,90,0.2286},{110,100,0.2059},{110,110,0.1404},{110,120,0.03968},{110,130,0},{110,140,0},{110,150,0.03968},{110,160,0.1404},{110,170,0.2059},{110,180,0.2286},{110,190,0.2059},{110,200,0.1404},{110,210,0.03968},{110,220,0},{110,230,0},{110,240,0.03968},{110,250,0.1404},{110,260,0.2059},{110,270,0.2286},{110,280,0.2059},{110,290,0.1404},{110,300,0.03968},{110,310,0},{110,320,0},{110,330,0.03968},{110,340,0.1404},{110,350,0.2059},{110,360,0.2286},{120,0,0.3605},{120,10,0.3319},{120,20,0.2495},{120,30,0.1230},{120,40,0},{120,50,0},{120,60,0.1230},{120,70,0.2495},{120,80,0.3319},{120,90,0.3605},{120,100,0.3319},{120,110,0.2495},{120,120,0.1230},{120,130,0},{120,140,0},{120,150,0.1230},{120,160,0.2495},{120,170,0.3319},{120,180,0.3605},{120,190,0.3319},{120,200,0.2495},{120,210,0.1230},{120,220,0},{120,230,0},{120,240,0.1230},{120,250,0.2495},{120,260,0.3319},{120,270,0.3605},{120,280,0.3319},{120,290,0.2495},{120,300,0.1230},{120,310,0},{120,320,0},{120,330,0.1230},{120,340,0.2495},{120,350,0.3319},{120,360,0.3605},{130,0,0.4532},{130,10,0.4210},{130,20,0.3285},{130,30,0.1865},{130,40,0.01221},{130,50,0.01221},{130,60,0.1865},{130,70,0.3285},{130,80,0.4210},{130,90,0.4532},{130,100,0.4210},{130,110,0.3285},{130,120,0.1865},{130,130,0.01221},{130,140,0.01221},{130,150,0.1865},{130,160,0.3285},{130,170,0.4210},{130,180,0.4532},{130,190,0.4210},{130,200,0.3285},{130,210,0.1865},{130,220,0.01221},{130,230,0.01221},{130,240,0.1865},{130,250,0.3285},{130,260,0.4210},{130,270,0.4532},{130,280,0.4210},{130,290,0.3285},{130,300,0.1865},{130,310,0.01221},{130,320,0.01221},{130,330,0.1865},{130,340,0.3285},{130,350,0.4210},{130,360,0.4532},{140,0,0.5158},{140,10,0.4817},{140,20,0.3833},{140,30,0.2325},{140,40,0.04752},{140,50,0.04752},{140,60,0.2325},{140,70,0.3833},{140,80,0.4817},{140,90,0.5158},{140,100,0.4817},{140,110,0.3833},{140,120,0.2325},{140,130,0.04752},{140,140,0.04752},{140,150,0.2325},{140,160,0.3833},{140,170,0.4817},{140,180,0.5158},{140,190,0.4817},{140,200,0.3833},{140,210,0.2325},{140,220,0.04752},{140,230,0.04752},{140,240,0.2325},{140,250,0.3833},{140,260,0.4817},{140,270,0.5158},{140,280,0.4817},{140,290,0.3833},{140,300,0.2325},{140,310,0.04752},{140,320,0.04752},{140,330,0.2325},{140,340,0.3833},{140,350,0.4817},{140,360,0.5158},{150,0,0.5567},{150,10,0.5215},{150,20,0.4199},{150,30,0.2643},{150,40,0.07340},{150,50,0.07340},{150,60,0.2643},{150,70,0.4199},{150,80,0.5215},{150,90,0.5567},{150,100,0.5215},{150,110,0.4199},{150,120,0.2643},{150,130,0.07340},{150,140,0.07340},{150,150,0.2643},{150,160,0.4199},{150,170,0.5215},{150,180,0.5567},{150,190,0.5215},{150,200,0.4199},{150,210,0.2643},{150,220,0.07340},{150,230,0.07340},{150,240,0.2643},{150,250,0.4199},{150,260,0.5215},{150,270,0.5567},{150,280,0.5215},{150,290,0.4199},{150,300,0.2643},{150,310,0.07340},{150,320,0.07340},{150,330,0.2643},{150,340,0.4199},{150,350,0.5215},{150,360,0.5567},{160,0,0.5820},{160,10,0.5462},{160,20,0.4429},{160,30,0.2848},{160,40,0.09086},{160,50,0.09086},{160,60,0.2848},{160,70,0.4429},{160,80,0.5462},{160,90,0.5820},{160,100,0.5462},{160,110,0.4429},{160,120,0.2848},{160,130,0.09086},{160,140,0.09086},{160,150,0.2848},{160,160,0.4429},{160,170,0.5462},{160,180,0.5820},{160,190,0.5462},{160,200,0.4429},{160,210,0.2848},{160,220,0.09086},{160,230,0.09086},{160,240,0.2848},{160,250,0.4429},{160,260,0.5462},{160,270,0.5820},{160,280,0.5462},{160,290,0.4429},{160,300,0.2848},{160,310,0.09086},{160,320,0.09086},{160,330,0.2848},{160,340,0.4429},{160,350,0.5462},{160,360,0.5820},{170,0,0.5957},{170,10,0.5596},{170,20,0.4556},{170,30,0.2963},{170,40,0.1009},{170,50,0.1009},{170,60,0.2963},{170,70,0.4556},{170,80,0.5596},{170,90,0.5957},{170,100,0.5596},{170,110,0.4556},{170,120,0.2963},{170,130,0.1009},{170,140,0.1009},{170,150,0.2963},{170,160,0.4556},{170,170,0.5596},{170,180,0.5957},{170,190,0.5596},{170,200,0.4556},{170,210,0.2963},{170,220,0.1009},{170,230,0.1009},{170,240,0.2963},{170,250,0.4556},{170,260,0.5596},{170,270,0.5957},{170,280,0.5596},{170,290,0.4556},{170,300,0.2963},{170,310,0.1009},{170,320,0.1009},{170,330,0.2963},{170,340,0.4556},{170,350,0.5596},{170,360,0.5957},{180,0,0.6000},{180,10,0.5638},{180,20,0.4596},{180,30,0.3000},{180,40,0.1042},{180,50,0.1042},{180,60,0.3000},{180,70,0.4596},{180,80,0.5638},{180,90,0.6000},{180,100,0.5638},{180,110,0.4596},{180,120,0.3000},{180,130,0.1042},{180,140,0.1042},{180,150,0.3000},{180,160,0.4596},{180,170,0.5638},{180,180,0.6000},{180,190,0.5638},{180,200,0.4596},{180,210,0.3000},{180,220,0.1042},{180,230,0.1042},{180,240,0.3000},{180,250,0.4596},{180,260,0.5638},{180,270,0.6000},{180,280,0.5638},{180,290,0.4596},{180,300,0.3000},{180,310,0.1042},{180,320,0.1042},{180,330,0.3000},{180,340,0.4596},{180,350,0.5638},{180,360,0.6000}};

interpf = 
  Interpolation[{{#[[1]] Degree, #[[2]] Degree}, #[[3]]} & /@ data];

SphericalPlot3D[interpf[x, y], {x, 0, π}, {y, 0, 2 π}, 
 BoxRatios -> Automatic, PlotRange -> All, Boxed -> False, 
 Axes -> False, PlotPoints -> 50]

SphericalPlot3D[1, {θ, 0, π}, {φ, 0, 2 π}, 
 ColorFunction -> (ColorData["SunsetColors", "ColorFunction"][
     interpf[#4, #5]] &), Mesh -> 10, 
 MeshFunctions -> {interpf[#4, #5] &}, ColorFunctionScaling -> False, 
 Boxed -> False, Axes -> False, PlotPoints -> 100, BoundaryStyle -> None]

enter image description here

enter image description here

$\endgroup$
8
  • $\begingroup$ You are a freaking legend, azerbajdzan!! Thank you so very much! Can I ask one more thing, please? Is there a way to include contour lines similar to what you see in ListContourPlot? If I'm asking too much then never mind. You have been such a great help!. $\endgroup$ Commented Nov 13, 2023 at 22:49
  • $\begingroup$ I edited my answer with adjusted mesh to be consistent with coloring... $\endgroup$ Commented Nov 13, 2023 at 22:54
  • $\begingroup$ Thank you ever so much! That's just great. You have really made someone's day! $\endgroup$ Commented Nov 13, 2023 at 22:59
  • 1
    $\begingroup$ @azerbajdzan Sorry for the newbie question but what do the slot designators #4 and #5 refer to when you reference interpf[#4,#5] for ColorFunction and MeshFunction? $\endgroup$
    – jmm
    Commented Nov 15, 2023 at 14:58
  • 1
    $\begingroup$ @jmm: Slots {#1,#2,#3,#4,#5,#6} correspond to {x, y, z, θ, φ, r}. $\endgroup$ Commented Nov 15, 2023 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.