MATLAB Answers

How to make a a certain range with different color in colorbar

10 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2020 年 8 月 8 日
コメント済み: Walter Roberson 2020 年 8 月 12 日
I created a a contour plot and I would like to make the range between -50 and 0 different than the range 0 and 50 as below. Anway to help please
[X,Y] = meshgrid(10:5:80,0:1:20);
Z = f([X(:), Y(:)]);
Z1 = reshape(Z,[21,15]);
figure
contour(X,Y,Z1,15000)
colormap hsv
colorbar
xlabel('\gamma (%)')
ylabel('\lambda (%)')
zlabel('m^{*}_{NPV} ($B)')

  0 件のコメント

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

採用された回答

Sudheer Bhimireddy
Sudheer Bhimireddy 2020 年 8 月 8 日

  8 件のコメント

表示 5 件の古いコメント
Yaser Khojah
Yaser Khojah 2020 年 8 月 9 日
It is better but wanted to show how it vareis between 0 and 50.
Sudheer Bhimireddy
Sudheer Bhimireddy 2020 年 8 月 9 日
First, your cmap array will be of size Nx3.
If I understand you correctly, you want to show the variation between 0 and 50, but not from 50 to 300.
If you have the indices for 0 and 50, you can edit the cmap array between the corresponding indices to show the variation and then can have same color for thereafter. Also know, that sometimes limiting the coloraxis (caxis([cmin cmax])) could be useful. If you want anyvalue after 50 to have the same color then caxis([min(z) 50]) will do the trick.
For Option 1, colormapeditor is a gui based method, so it is purely manual.
Yaser Khojah
Yaser Khojah 2020 年 8 月 9 日
Thanks Sudheer, I want exactly what I have with additional variation between 0 and 50. The range is very small which I’m struggling to present.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 8 月 9 日
The above function requires that the positions be defined in relative terms, 0 to 1, rather than in absolute terms. You would have to decide ahead of time what your caxis() is going to be, and use proportional positions through that range,
relative_position = (data_x - min_to_map)./(max_to_map - min_to_map)

  8 件のコメント

表示 5 件の古いコメント
Walter Roberson
Walter Roberson 2020 年 8 月 12 日
You posted a .xlsx but your code loads a .mat ?
Yaser Khojah
Yaser Khojah 2020 年 8 月 12 日
Oh I’m sorry I just added the xsl for you since I though I can’t upload the mat file.
Walter Roberson
Walter Roberson 2020 年 8 月 12 日
levels = [-700 -600 -500 -400 -300 -200 -100 -50 -40 -30 -20 -10 0 10 20 30 40 50 100 200 300];
[a,b] = contourf(X, Y, Z1, levels);
This will not in itself create new colormap entries for the various levels, but it will outline them more clearly.
To create new colormap entries, you have to follow the strategy I outlined above, of creating a colormap with replicated slots.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by