How is the color of a patch in a surface plot determined?

2 views (last 30 days)
I am creating some surface plots, and I wanted to know how MATLAB determines the color of a surface plot. For example, if I create the following surface plots:
x=[0 2 2 0 0]
y=[0 0 2 2 0]
p1=patch(x,y,3)
figure
p2=patch(x,y,6)
You will notice that despite the fact that I used different values for the third argument, the colors of the two patches are the same color.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
For every (x,y) value there is a corresponding z value; and for every z value, there is a C coordinate where C is the color determined from the colormap. For example, suppose we take a bird's eye view of a surface plot of peaks:
s=surf(peaks(5));
view(2)
colorbar
and then denote each of the corners with a visible marker:
set(s,'marker','s','markersize',14,'markerfacecolor','flat')
As you can see, the color of each value of the surface plot is determined by the color of the lower-left hand marker. If we allow the surface plot to evenly shade itself:
shading interp
MATLAB takes the colors in each of the corners and fills in the remainder of the plot accordingly. Now, if we examine the abovementioned p1 and p2 patches and assign each of the points a different color:
x=[0 2 2 0 0]
y=[0 0 2 2 0]
p3=patch(x,y,3)
colorbar
set(p3,'cdata',[1 2 3 4 5])
You will noticed that the p3 patch plot is not the same color in the above mentioned p1 or p2 patches. However, if we shade the p3 patch and make the corners visible:
shading interp
set(p3,'marker','s','markersize',14,'markerfacecolor','flat')
you will notice that the color of the p3 patch is not the same color that appears in the lower-left hand marker. This is due to the fact that since the origin contains two overlapping points with two different corresponding color values, the color of the first point is expressed in the patch.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!