-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!