Colorbar in an other figure...

2 visualizaciones (últimos 30 días)
Nick
Nick el 1 de Mzo. de 2012
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by