1
votes

I would like to ask the community for help in creating a Matlab-like 3D surf plot with a colormap but in Mathematica. To make the question more specific lets say that we have a set of numbers in 3D space and to each point some function value c is asigned:

{{x1,y1,z1,c1},{x2,y2,z2,c2},...,{xN,yN,zN,cN}} 

These points lay on a surface in 3D e.g. a sphere. Now in matlab if these points are properly represented as matrixes X, Y, Z, C we can simpliy plot this surface with

k = 5;
n = 2^k-1;
[x,y,z] = sphere(n);
c = magic(2^k);
surf(x,y,z,c);
colormap gray
axis equal

What is important here are the function values which can be read of the plot thanks to the colorbar.

Now the question to the community is:

Can we produce such a plot in Mathematica (with a colorbar - this is the important part)???

I searched for a solution on the web without luck. I looked at things like ListPlot3D, ListSurfacePlot3D, ListPointPlot3D but to these functions you can only pass a surface without the corresponding point values (unless there is something I don't understand).

Does anyone know a solution, a way to create such plots in Wolfram Mathematica?

1

1 Answers

2
votes

You can use ColorFunction to specify, well, the color function :

ParametricPlot3D[{Sin[t] Cos[f], Sin[t] Sin[f], Cos[t]}, {t, 0, Pi}, {f, 0, 2 Pi} , 
 ColorFunction -> Function[{x, y, z, t, f}, RGBColor[z]]]

plot

Another way is to use textures; I will use the data you generated with the other software.

{x, y, z, c} = Import["/tmp/sphere.mat"];

The texture we want to apply is c (actually rotated 90 degrees)

ArrayPlot[c]

texture

ParametricPlot3D[{Sin[t] Cos[f], Sin[t] Sin[f], Cos[t]}, {t, 0, Pi}, {f, 0, 2 Pi}, 
  PlotStyle -> Texture[ Rotate[ArrayPlot[c], Pi/2]], Lighting -> "Neutral"]

sphereM