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

 Akzeptierte Antwort

Andrew Newell
Andrew Newell am 1 Mär. 2012

0 Stimmen

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 Kommentare

Nick
Nick am 1 Mär. 2012
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.
Andrew Newell
Andrew Newell am 1 Mär. 2012
Did you read the second part of my answer?
Nick
Nick am 1 Mär. 2012
I jsut did now! haha... it did not show up earlier!
Thanks I will do that!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by