define a sequential discrete color map with first color white.

51 ビュー (過去 30 日間)
Damith
Damith 2015 年 4 月 15 日
回答済み: Makarand 2018 年 4 月 27 日
Hi,
I need to define a color map with 8 different sequential discrete colors like below. But, the first colot should be while. How can I define a color map and include in the MATLAB code below.?
Any help is highly appreciated.
Thanks in advance.
figure;
pcolor(lon,lat,t2);
shading interp
colorbar

採用された回答

Image Analyst
Image Analyst 2015 年 4 月 15 日
Try this:
cmap = jet(20)
cmap = flipud(cmap(1:10,:));
cmap(1,:) = [1,1,1];
colormap(cmap);
colorbar
  2 件のコメント
Damith
Damith 2015 年 4 月 15 日
Thanks. I tried it. This is more close to what I wanted. See the modified code below and the figure it produced.
Few more things I need to accomplish.
1) I need to remove the tick marks from the colorbar but it has not removed even the last 3 lines in the code intended to do.
2) I need to graduate the colorbar from 0 (zero) to 20.
3) I need to know whether I can place the colorbar bottom of the figure?
Any help is appreciated to accomplish the above tasks.
Thanks.
figure;
pcolor(lon,lat,t2);
shading interp
cmap = jet(20);
cmap = flipud(cmap(1:10,:));
cmap(1,:) = [1,1,1];
colormap(cmap);
hcb=colorbar
set(hcb,'YTick',[])
colorbar
Image Analyst
Image Analyst 2015 年 4 月 16 日
Do you know the RGB values for each of the 10 colors? If so, just assign them to each row of cmap.

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

その他の回答 (2 件)

Chad Greene
Chad Greene 2015 年 4 月 16 日
編集済み: Chad Greene 2015 年 4 月 16 日
The colormap you uploaded in your original question looks a lot like a Cynthia Brewer colormap, which Stephen Cobeldick has made into a nice little function called brewermap. You'll notice the first value in that colormap you uploaded is not pure white. Here's how you can create the 8-level brewer map with the brewermap function, and if you want to force the first value to white, you can do that too.
pcolor(3.5*abs(peaks(1024)))
shading interp
% Create colormap:
map = brewermap(8,'GnBu');
map(1,:) = [1 1 1]; % optionally force first color to white
colormap(map)
cb = colorbar('location','south');
caxis([0 20]) % sets colorbar limits
set(cb,'xtick',[])
% another colorbar:
cb2 = colorbar('location','northoutside');
The reason your set(hcb,'YTick',[]) did not work is because you followed it by calling a new colorbar. And you can set the colorbar limits from 0 to 20 by caxis([0 20]). For colorbar location you may alternatively want 'southoutside'.

Makarand
Makarand 2018 年 4 月 27 日
if you have unequal intervals then you can check Recolor_pcolor

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by