Colorbar in an other figure...

2 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by