How can I apply different colormaps to different axes on the same figure in MATLAB?

I am plotting multiple surfaces and/or displaying multiple indexed images within the same figure on different axes. I would like to apply different colormaps to different axes to better visualize each image.

 Accepted Answer

The ability to apply different colormaps to different axes objects on the same figure is not currently available in MATLAB. The reason for this is that the "colormap" is a property of the figure, and not of the axes.
For more information refer to the following Technical Note on "Using Multiple Colormaps in a Single Figure":
As an alternative to the methods provided in this Techincal Note, you can convert your indexed images into RGB images that would be displayed the same way regardless of the colormap. To do this follow these steps:
1. Download the attached file "index2rgb_direct.m", and save it in a local drive on your computer.
2. After saving the above file in your MATLAB current directory, you can do the following:
b = rand(4)*64; % or any indexed image you have
image(b);
colormap(hsv(64));
b2 = index2rgb_direct(b, hsv(64));
figure
image (b2)
The two images generated will be identical; "b" is an indexed image, and "b2" is the RGB version of the same image that will be displayed the same way regardless of the figure's colormap.
You can use any of your images instead of "b", and you can replace "hsv(64)" with any colormap you are using.

More Answers (0)

Categories

Products

Release

R14SP1

Community Treasure Hunt

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

Start Hunting!