How to create personalized colormap that starts from a specified value

2 ビュー (過去 30 日間)
Reza Lashani
Reza Lashani 2022 年 11 月 22 日
コメント済み: Reza Lashani 2022 年 11 月 22 日
Hello everyone
I've plotted a surface which it's value when z>=0 is what I want to report. When I use zlim([0 n]) command, the colormap won't update and the peaks are not distinguishable as you see in pictures attached. Is there a way that I could create a personalized colormap which it starts from z=0 and vary with z value? (For example in the grey gradient in pictures attached, the color of z=0 becomes black and the color of highest value of z becomes grey)
Thanks and regards

採用された回答

Florian Bidaud
Florian Bidaud 2022 年 11 月 22 日
Hi
If Z is the map you plot, you can replace all the negative values by 0 like that :
Z = [0 1 8; -1 5 10;-6 -3 14]
Z = 3×3
0 1 8 -1 5 10 -6 -3 14
Z_negative = Z;
Z_negative(Z<0) = 0
Z_negative = 3×3
0 1 8 0 5 10 0 0 14
And then plot this new map
If you don't want these values at all, you can replace them by NaN :
Z = [0 1 8; -1 5 10;-6 -3 14];
Z_negative = Z;
Z_negative(Z<0) = NaN
Z_negative = 3×3
0 1 8 NaN 5 10 NaN NaN 14
  3 件のコメント
Florian Bidaud
Florian Bidaud 2022 年 11 月 22 日
編集済み: Florian Bidaud 2022 年 11 月 22 日
I'm not sure what you really want. zlim removes the values from the plot as follows:
Maybe what you want is changing the color scale ? In this case, you need to use caxis([0 n]).
x = [0 1 2 3 4];
y = [0 1 2 3 4];
z = [1 5 -2 4 6;-1 5 -6 7 8; 1 2 5 9 10; -2 -3 -4 -5 -7;5 -1 6 -2 3];
surf(x,y,z)
zlim([0 max(max(z))])
caxis([0 max(max(z))])
Reza Lashani
Reza Lashani 2022 年 11 月 22 日
thank you very much Florian. It is exactly what I wanted.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by