I'm making a figure with two subplots in Matlab 2017a. Each subplot has a different image with a different colormap. I want to have a colorbar for each subplot that matches the colormap of that subplot.
The problem is the colorbar of my first subplot does not match its colormap. Instead the colorbar of the first subplot incorrectly matches the colormap of the second subplot.
I'm using freezeColors and cbfreeze for each subplot as described in other questions on this forum. I am correctly getting different colormaps for each subplot, and the colorbar for the second subplot is correct, but the colorbar for the first subplot is not correct. What am I doing wrong?
Here is code that demonstrates the problem:
load clown.matimage(X)load penny.matimage(P)figure(1)hFig=gcf;set(hFig, 'Position', [50 50 300 500]);subplot(2,1,1)image(X);colormap('gray')hcb1=colorbar;freezeColorscbfreeze(hcb1)subplot(2,1,2)image(P);colormap('jet')hcb2=colorbar;freezeColorscbfreeze(hcb2)
Here is what the resulting figure looks like with the incorrect colorbar for the first subplot:
Best Answer