フィルターのクリア

Align colorbar ticks with corresponding colors

12 ビュー (過去 30 日間)
yoni verhaegen
yoni verhaegen 2018 年 6 月 6 日
回答済み: Sindhu Yerragunta 2018 年 6 月 18 日
Hi all,
I have the following script, which plots the corresponding plot. How can I change this so the discrete colors match the used ticks in both the plot and the colorbar? E.g. the dark purple for 14.3-15, then next blueish/purple from 15-16 and so on.
Thanks!
x1=data(:,1);
y1=data(:,2);
z1=data(:,3);
[XI,YI] = meshgrid(x1,y1);
ZI = griddata(x1,y1,z1,XI,YI);
surf(XI,YI,ZI);
shading interp;
set(gca, 'YScale', 'log');
colormap(parula(10));
cbh = colorbar ; %Create Colorbar
cbh.Ticks = [14.3 15 16 17 18 19 20] ; %Create ticks
box on;
grid on;
set(gca,'Layer','Top');
view([90 90]);
ylim([7e-15 1.1e-12]);
xlim([4.5e-17 7.25e-17]);
caxis([14 21]);
  1 件のコメント
Jan
Jan 2018 年 6 月 7 日
編集済み: Jan 2018 年 6 月 7 日
I do not understand: "the discrete colors match the used ticks in both the plot and the colorbar". The colors of the diagram and the colorbar are matching already. Which "ticks" do you mean? The ticks of the colorbar? Then the "20" is written with yellow on white? This would be a bad idea, wouldn't it?

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

回答 (1 件)

Sindhu Yerragunta
Sindhu Yerragunta 2018 年 6 月 18 日
Hi Yoni,
This misalignment occurs due to the fact that if suppose there are 10 colors in the colormap, but only 9 bins to put them in.
In general, for a vector containing N ticks, there are N-1 intervals.
In your case reducing the number of colors in the colormap to 7 should help,
colormap(parula(7));
Hope this answers the query.
-Sindhu

カテゴリ

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