# Plotting an array of data onto a sphere [duplicate]

See the link to plot at the bottom of this post, it is a function of the spherical coordinates theta and phi. It is generated by MatrixPlot of an Array of data. I would like to plot this onto a sphere of arbitrary radius. Any ideas? Here's the code used to generate the plot.

  lp=1;
a = 1;
e1 = a {-Sqrt*lp/2 + Sqrt/2, lp/2 - 3/2};
e2 = a {-Sqrt*lp/2 + Sqrt, lp/2};
e3 = a*lp {-Sqrt/2, 1/2};

phi1 = ArcTan[e1[], e1[]] - phi0 + Pi/2;
phi2 = ArcTan[e2[], e2[]] - phi0 + Pi/2;
phi3 = ArcTan[e3[], e3[]] - phi0 + Pi/2;

c1 = (1 - 3*(Sin[theta0])^2*(Cos[phi1])^2)/(Norm[e1]^3);
c2 = (1 - 3*(Sin[theta0])^2*(Cos[phi2])^2)/(Norm[e2]^3);
c3 = (1 - 3*(Sin[theta0])^2*(Cos[phi3])^2)/(Norm[e3]^3);

Clear[phi0];
Clear[theta0];
Clear[colorMat];
count1 = 0;
count2 = 0;
step = 0.003;
nstepsPhi = Floor[(2*Pi - 0)/step + 1];
nstepsTheta = Floor[(Pi - 0)/step + 1];
colorMat = ConstantArray[0, {nstepsPhi, nstepsTheta}];
Do[
count1 = count1 + 1;
count2 = 0;
Do[
count2 = count2 + 1;
thing = (c1^2 - c2^2 - c3^2)/(2*c2*c3);
If[thing>=0 && thing<=1, colorMat[[count2, count1]] = 0.1 ,
colorMat[[count2, count1]] = 1]
, {phi0, 0, 2*Pi, step}]
, {theta0, 0, Pi, step}]

MatrixPlot[colorMat]


Solution

First, MatrixPlot includes a small border around the image which appears on the final sphere. Even using the option PlotRangePadding->None, this appeared. So, instead let's use Image to create the image.

img = Image[Map[If[# == 1, {0.94, 0.49, 0.02}, {0.87, 0.77, 0.43}] &,
Transpose[colorMat], {2}]];


In this bit of code, the If[#==1, rgb1,rgb2]& business can be interpreted as follows: The colorMat is a 0-1 matrix and we want to change each element into an RGB triple. If the # is 1, we change to rgb1 and If the # is 0, we change it to rgb2. The # / & business refers to a pure function, as you can read about in the Wolfram documentation.

Now, let's map that onto the sphere.

ParametricPlot3D[{Cos[theta] Sin[phi], Sin[theta] Sin[phi], Cos[phi]},
{theta, -Pi, Pi}, {phi, 0, Pi}, Mesh -> None, PlotPoints -> 101,
Boxed -> False, PlotStyle -> Texture[img],
Lighting -> "Neutral", Axes -> False] • It appears that your image was generated with Mathematica. Do you have the code? Regardless, this type of thing has been discussed before. You might be able to adapt the techniques listed here: mathematica.stackexchange.com/questions/15047/… Mar 12 '13 at 16:57
• If you search this site, you'll find several similar questions. Here's one: mathematica.stackexchange.com/questions/52/… Mar 12 '13 at 17:00
• Yes. I'll add it now :) just had a look at that link and it boggles my mind a bit but i'll see what sense i can make of it. thanks for the reply.
– Tom
Mar 12 '13 at 17:04
• Um, how do I add mathematica code so it looks pretty like in all the other questions? =S
– Tom
Mar 12 '13 at 17:09
• @ThomasJebbSturges Just indent the code 4 spaces. Mar 12 '13 at 17:11