Colorbar in an other figure...

Here is a little problem I have encountered multiple times... usually I deal with it, but this time I really want it to be working.
I would like to display the colorbar (from an imagesc call) in a different figure or next to a different set of axes.
Here is an example: - I have 5 images that I rescale to the same colormap. - I do not want all the figures to show a colormap since they are all similar, but I also want all the images to look similar (in size) so that it is easier for comparison purposes.
In my opinion, the nicest thing is to do a subplot of 2x3, put the 5 images in 5 plot areas, and the colorbar in the 6th plot region.
Unfortunately, even by doing a colorbar('peer',axis_handle) it does not show in this last subplot, but rather in the plot of the actual axis_handle.
Is there really not a simple way of doing this?!
Thanks

 Accepted Answer

The really simple way to do it is to just grab the bar with the mouse and move it. Do you want to automate this?
If you do want to automate it, you can play around with the properties of the graphics handles. Here is an example where I create the colorbar for subplot 1 and move it to subplot 2:
h1 = subplot(121);
surf(peaks(30));
cbar_axes = colorbar;
h2 = subplot(122);
%Get the relative positions of the two subplots and use to adjust colorbar position
v1 = get(h1,'OuterPosition');
v2 = get(h2,'OuterPosition');
va = get(cbar_axes,'OuterPosition');
set(cbar_axes,'OuterPosition',va+v2-v1)
axis off

3 Comments

Hi Andrew,
Sorry, yes I should have precised that I would like to do this in a function. I do not like to bother with "edit plot"... not the fastest tool in Matlab.
Besides, I would have to also redisplay the image so that it is not crunched up on one side...
There might not be a way to automate this, I'm not sure... I always end up using Gimp at the end when preparing my figures for reporting.
Did you read the second part of my answer?
I jsut did now! haha... it did not show up earlier!
Thanks I will do that!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!