-fmesh- face and edge color different for neg, 0, pos Z values

1 次查看(过去 30 天)
Hi folks!
I am making a 3-D plot using -fmesh-.
I would like to make the face and edge colors different for negative, zero, and positive Z values.
I have tried the following so far:
s=fmesh(@(X,Y) X./(Y.*(1-X)-1));
s.FaceColor = 'interp';
s.EdgeColor = 'white';
EC = s.EdgeColor;
FC = s.FaceColor;
But, I am not sure how to creat the conditional statement to access 1x1 FunctionSurface to make these changes.
I tried something like below, which did not work, but the idea was to possibly plot only positive ZData values.
s.ZData = s.ZData(s.ZData >= 0);
What I want to obtain are:
  1. Have three distinct -s.EdgeColor- and -s.FaceColor- for negative, zero, and positive Z values.
  2. Draw three separate -fmesh- plots only for negative, zero, and positive Z values all separately.
Thanks in advance!

采纳的回答

Walter Roberson
Walter Roberson 2022-9-1
You can color by z by creating a colormap that divides the range up into segments, and setting the first half to the color for negative, the last half to the color for positive, and the middle to the color for zero.
Note that this will end up plotting a range of values with the zero color, rather than the values that are exactly zero.
FunctionSurface objects do not have the ability to set the color for individual locations.
s=fmesh(@(X,Y) X./(Y.*(1-X)-1));
s.FaceColor = 'interp';
s.EdgeColor = [0 .3 0];
[minz, maxz] = bounds(s.ZData(:));
zrange = max(abs([minz, maxz]));
negcol = [0 0 0.7];
zcol = [.8 .8 .8];
poscol = [.7 0 0];
cmap = repelem( [negcol; zcol; poscol], [127 1 128], 1);
caxis([-zrange zrange]);
colormap(cmap)
  7 个评论
Walter Roberson
Walter Roberson 2022-9-2
[C, h]=contourf(X,Y,Z);
You cannot do that directly. fmesh() gives you vectors of XData and YData and ZData, but for contourf() you need to have 2D arrays of data.
You could switch out of using fmesh() into creating your own grids and using contour3(), but if you wanted to proceed with fmesh() you would have to use scattered interpolant techniques to create the data to contour

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by