Change colour of points in plot3 with increasing z value

71 次查看(过去 30 天)
Hi I have a set of x values, set of y values and for each x,y I have a z value. I have to plot them as shown in the attached figure. I am using plot3 to plot that graph. I want to change the colour of the points according to the value of z. The more the value of z, more is the intensity. Any help will be appreciated.

回答(2 个)

Mike Garrity
Mike Garrity 2016-2-10
No, plot3 only supports a single color. You can use other graphics functions. The "traditional" one for this purpose is actually rather surprising. It's the patch function, which is designed for drawing filled polygons.
Consider this example:
x = cos(theta);
y = sin(theta);
z = theta;
plot3(x,y,z)
I can draw it colored by Z like this:
cla
patch([x nan],[y nan],[z nan],[z nan],'EdgeColor','interp','FaceColor','none')
What's going on here is the following:
  • The 4th arg says to use Z for color data
  • The EdgeColor=interp says to interpolate the color data as the edge color
  • The FaceColor=none says to not fill the polygon. Just draw the edges
  • The nans say not to connect the last point to the first point.
There are a couple of other options, but that's probably what most old-school MATLAB programmers use.
  1 个评论
Mahi Nazir
Mahi Nazir 2016-2-10
Thanks Mike. I want discrete data points in z, so I use plot3(x, y, z, '*') How will I get these discrete points using patch?

请先登录,再进行评论。


Steven Lord
Steven Lord 2016-2-10
Based on the picture, which did not have lines connecting the points, I think SCATTER3 is the function you're looking for.
  2 个评论
Mike Garrity
Mike Garrity 2016-2-10
Yes, Steve's right. That's the better bet.
That'll teach me to not look at the picture!
Mahi Nazir
Mahi Nazir 2016-2-10
编辑:Mahi Nazir 2016-2-10
Thank you Steven. How to set the colour intensity based on the value of z. If say, z= 8 for both (x1, y1) and say (x3, y3), z should be plotted in the same colour when z has the same value. So that the plot is colour coded. Can you cite an example with the kind of data I have please. My x is (nx1), y is (nx1) and z obviously is (nx1).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by