How to apply different color cards in different subtitles?

I do more or less the following:

figure for ii=1:4 subplot(2,2,ii) imshow(image(ii)) hcb = colorbar; switch ii case 1 colormap(myMap) set(hcb,'YTickLabel', .. ) set(hcb,'YTick', .. ) case 2 colormap(myMap) set(hcb,'YTickLabel', .. ) set(hcb,'YTick', .. ) case 3 colormap(myMap) set(hcb,'YTickLabel', .. ) set(hcb,'YTick', .. ) case 4 colormap(aDifferentMap) set(hcb,'YTickLabel', .. ) set(hcb,'YTick', .. ) end end 

It seems to me that calling colormap(aDifferentMap) for the fourth plot ( ii=4 ) twists things for the previous three graphs: in my last figure, all the color panels have aDifferentMap colormap, as well as some problems with the YTick attribute.

If I comment on colormap(aDifferentMap) in case 4, everything works well (except for the fourth subtitle, which will have the wrong color palette and without Ytickes).

How can I handle this? How to set subplot(2,2,4) properties without affecting 1: 3 subheadings?

+5
source share
3 answers

For Matlab 2014a and up , Phil Goddard's answer applies, and you need to use, for example. freezeColors from FileExchange.


In Matlab 2014b, the problem was solved by updating the graphics engine to version HG-2 . Now the color palette affects all the axes in the figure, if you have not set the color map of the axes separately. (from doc )

 figure ax1 = subplot(2,1,1); surf(peaks) colormap(ax1,spring) ax2 = subplot(2,1,2); surf(peaks) colormap(ax2,winter) 

enter image description here

+5
source

Colormap is a property of a shape, not an axis, so changing it for a subtitle changes it for all sub-patches.

See Using multiple color folders in a single shape for an example solution.

+1
source

You can use ind2rgb if you just want to show images with different color maps in the picture:

 load flujet; subplot(221); image(ind2rgb(X, gray(63))); subplot(222); image(ind2rgb(X, jet(63))); subplot(223); image(ind2rgb(X, hot(63))); subplot(224); image(ind2rgb(X, copper(63))); 

However, different color panels still cannot be displayed in earlier versions of MATLAB.

0
source

Source: https://habr.com/ru/post/1216403/


All Articles