Changing the default colorbar
7 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 25 Jul 2011
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 Comments
James
on 25 Jul 2011
1 Comment
Walter Roberson
on 25 Jul 2011
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.
See Also
Categories
Find more on Color and Styling in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!