Basic question about coloring of a 3d plot

2 views (last 30 days)
Marc
Marc on 5 Jul 2013
Hi,
I have the following question:
I have a 3D plot which shows the dependencies of 3 variables. One of these variables is the wavelength of light. Is it possible to have one specified color for each wavelength along the wavelength axis of my plot?
For example: if the wavelength equals 530 nm, then I would want the plot to be green for all points where wavelength = 530nm.
I am looking forward to, and appreciate your answers!
Kind regards, Marc

Answers (2)

Kelly Kearney
Kelly Kearney on 5 Jul 2013
Some more details about your plot would help... are you plotting points? Lines? Surfaces? A scatter plot could help with points; a patch with facecolor and/or edgecolor set to interp could help with lines or surfaces.
  2 Comments
Kelly Kearney
Kelly Kearney on 5 Jul 2013
It would be helpful if you could comment on a specific answer rather than adding a new answer yourself. But in response to your clarification...
The fourth input to mesh specifies the color to plot the surface. For example, the following colors the mesh according to the x-coordinate, which I'm assuming represents wavelength:
z = peaks;
[x,y] = meshgrid(linspace(400,750,49), 1:49);
mesh(x,y,z,x);
colorbar;
Getting your colormap to reflect the visible spectrum is a little trickier using Matlab's native colormaps. Using one of my own functions (available here) along with this color palette table will accomplish it pretty easily though:
cptcmap('visspec', 'mapping', 'direct');
Marc
Marc on 5 Jul 2013
Hi Kelly,
I am sorry for having posted an answer and not commented on yours. I am new to this forum and did not know about the difference between the two. In the future, I will use the commenting and answer options accordingly.
I tried what you posted, setting the wavelength axis as the fourth input to mesh, but I am only getting a "red" plot.
I will read through the links you provided and try with that information - thank you very much!
If I don't get it to work, I'll let you know and ask for more specific help.
Marc

Sign in to comment.


Marc
Marc on 5 Jul 2013
Hi Kelly,
I am using mesh(x,y,z), if that is what you mean.
Marc

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!