Changing the default colorbar
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a two-dimensional matrix which is basically an aerial image of some land "pixels" and ocean "pixels". The land pixels are given a value of -9999 by default and the ocean pixels have values from zero to approximately 250. I want to use the standard colormap "jet" when using the image() function. However, is there a way to set the land pixels (-9999) to be black (rather than the default dark blue)?
Any help would be greatly appreciated. Thanks,
James
0 件のコメント
回答 (2 件)
Walter Roberson
2011 年 7 月 25 日
No. The "jet" colormap does not contain black, so as long as you restrict yourself to "jet" you are not going to be able to do this.
If you augment the jet colormap with one more entry then you could do it, with appropriate mapping of the data.
One alternative is to overlay an all-black image on top of the other image, and set the AlphaData property of the top image such that the patch is transparent (AlphaData zero) where there is no land.
0 件のコメント
James
2011 年 7 月 25 日
1 件のコメント
Walter Roberson
2011 年 7 月 25 日
In the below, I will rely upon your indication that your regular values are in the range 0 to 250. The below code will produce a distorted image if your range is significantly narrower or has values exceeding 254.
img = uint8(YourMatrix);
img(YourMatrix < 0) = 255;
At this point, your data has been discretized to uint8, and all of the original negative values have been set to 255. I choose to do it this way instead of shifting the other values "up" to make room for the black in order to allow the data cursor to function.
Now we set the color map to include black:
cmap = jet(256);
cmap(end,:) = [0;0;0]; %black
colormap(cmap); %activate it.
参考
カテゴリ
Help Center および File Exchange で Color and Styling についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!