- 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.
Change colour of points in plot3 with increasing z value
159 visualizaciones (últimos 30 días)
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.
Mike Garrity el 10 de Feb. de 2016
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;
I can draw it colored by Z like this:
patch([x nan],[y nan],[z nan],[z nan],'EdgeColor','interp','FaceColor','none')
What's going on here is the following:
There are a couple of other options, but that's probably what most old-school MATLAB programmers use.