How can I divide the colorbar into just two ranges?

80 ビュー (過去 30 日間)
mohamad shirgholami
mohamad shirgholami 2021 年 6 月 11 日
回答済み: DGM 2021 年 6 月 11 日
How can I set the colorbar to show me only two ranges, for example one smaller than 0.05 and the other larger than 0.05?

回答 (2 件)

Cris LaPierre
Cris LaPierre 2021 年 6 月 11 日
編集済み: Cris LaPierre 2021 年 6 月 11 日
The number of colors is controled by your colormap. However, MATLAB spreads the colormap evenly over the range of data plotted. If you want the transition to occur as a specific value, you will likely need to manually specify the color property of your figure.
Here's an example using surf.
p = peaks;
C = p>=0.05;
surf(p,C+1)
colormap(parula(2))
colorbar('Ticks',[1,1.5,2],'TickLabels',[-10,0.05,10])
The actual solution will depend greatly on the type of figure you are tyring to create.

DGM
DGM 2021 年 6 月 11 日
One way is to specify the colormap and caxis(); consider the example
[x y z] = sphere(30);
surf(x,y,z);
axis equal
datarange = [-1 1];
breakpoint = 0.5;
ctlen = 256;
colors = [0 0 1; 0 1 1];
pos = (max(datarange)-breakpoint)/diff(datarange);
n = [floor(ctlen*(1-pos)) ceil(ctlen*pos)];
cmap = [repmat(colors(1,:),[n(1),1]); repmat(colors(2,:),[n(2),1])];
colormap(cmap);
caxis(datarange)
colorbar
Doing it this way allows you to control the breakpoint position independently of the caxis endpoints.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by