-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:
- Have three distinct -s.EdgeColor- and -s.FaceColor- for negative, zero, and positive Z values.
- Draw three separate -fmesh- plots only for negative, zero, and positive Z values all separately.
Thanks in advance!
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!