MATLAB subplot: how to have 1 colorbar for both images?

  • #1
1,235
18
Title says it all. I have two matrices representing 2D surfaces, and I am using subplot to compare them in the same plat area, however, each has its own colorbar so comparison is not so easy to do by eye.

I'm pretty weak at figure handles, can someone give me a hint to do this? Thanks

Code:
subplot(1,2,1); h1 = pcolor(final); 
set(h1,'EdgeAlpha',0); colorbar
subplot(1,2,2); h2 = pcolor(initial);
set(h2,'EdgeAlpha',0); colorbar

Thanks
 
Physics news on Phys.org
  • #2
scale each image the same and then turn off one of the colorbars, they are not necessary for each subplot
 

1. How do I create a subplot with one colorbar for two images in MATLAB?

To create a subplot with one colorbar for two images in MATLAB, you can use the subplot function and specify the 'position' property for each subplot. Then, use the colorbar function to add a shared colorbar to the subplot.

2. Can I customize the placement of the colorbar in a subplot?

Yes, you can use the location property of the colorbar function to specify where the colorbar should be placed within the subplot. You can also use the 'Location' property of the subplot function to adjust the size and position of the subplot itself.

3. How do I adjust the colorbar limits for both images in a subplot?

To adjust the colorbar limits for both images in a subplot, you can use the caxis function. First, specify the limits for the colorbar using caxis([min max]), then call colorbar to update the colorbar in the subplot.

4. Can I have a different colormap for each image in a subplot with a shared colorbar?

Yes, you can use the caxis function to set the limits for each image's colormap, and then use colormap to specify the desired colormap for each image. The shared colorbar will adjust accordingly.

5. Is it possible to have a subplot with a shared colorbar for multiple figures?

No, it is not possible to have a shared colorbar for multiple figures. Each figure has its own colorbar, so if you want to have a shared colorbar, the images must be in the same figure.

Suggested for: MATLAB subplot: how to have 1 colorbar for both images?

Replies
2
Views
1K
Replies
4
Views
1K
Replies
1
Views
1K
Replies
9
Views
2K
Replies
1
Views
747
Replies
2
Views
1K
Replies
5
Views
690
Replies
5
Views
2K
Back
Top