quantized colorbar

11 ビュー (過去 30 日間)
Jonathan
Jonathan 2011 年 9 月 7 日
I would like a colorbar that only shows the colors of numbers that exist in the dataset.
Example:
x = -2*pi:0.01:2*pi;
y = x;
[X Y] = meshgrid(x,y);
Z = sign(round(cos(X).*cos(Y)));
imagesc(x,y,Z);colorbar;
There are only 3 possible numbers in the output matrix. Unfortunately, the colorbar will still show a full gradient.
I would appreciate a method for generating a colorbar with only the levels that are present.
  1 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 9 月 7 日
+1, well worded clear and concise question

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

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 9 月 7 日
X = sign(round((rand(10)-.5)*2));
imagesc(X);
un_X = unique(X);
colormap(cool(length(un_X)));
H = colorbar;
set(H,'ytick',un_X);
Manually set the colormap and the colorbar's ytick to the unique values of X.
  3 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 9 月 7 日
I saw that after I posted, see edit.
Jonathan
Jonathan 2011 年 9 月 7 日
Answered both the question I had, and the one I hadn't thought of.
Thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by