How to fix a colormap
19 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
the following toy problem
figure; hold on;
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z);
colorbar;
zlim([-1,1]);
generates a colored figure. I would like to keep these colores "fixed".
However, when I add another surf plot as follows
Znew = Z+5;
surf(X,Y,Znew);
the colors change.
Thanks for any help!
0 件のコメント
採用された回答
Cris LaPierre
2021 年 11 月 4 日
Your colormap isn't changing, but by default MATLAB scales the colormap to the range of data in the plot. If your first surf plot, the Z data ranges from -2:2. So when that is the only plot, blue corresponds to -2 and yellow to 2.
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z);
colorbar
However, in your second surface, Znew ranges from 3 to 7. With both surfaces on the plot, blue still corresponds to -2, but now 7 corresponds to yellow. 2 now corresponds to turquoise.
Znew = Z+5;
figure
surf(X,Y,Z);
hold on
surf(X,Y,Znew);
hold off
colorbar
So before we can say how to fix the color scaling, could you explain what it is you want to happen?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!