1
votes

I am trying to line up a plot of a signal with an image where the image has a colorbar. The colorbar causes the axes to be offset horizontally. My intuitive approach would be to fix the size of figures to something, like in Gnuplot with papersize. However, not sure which would be the best fit here.

To Adjust Scaling to Square in Full Screen Mode of Matlab?

I want to maintain the relations between the two figures. I cannot use squareform in the first figure for some reason, while I can in the latter figure. Code

figure

ax2=subplot(2,2,2); 
plot(mat2gray(pdist(data, 'correlation')));
title('Corr pdist');
cbar2 = colorbar(ax2);
xlim([0 size(mat2gray(pdist(data, 'correlation')),2)]);
set(cbar2, 'Visible', 'off');

ax4=subplot(2,2,4); 
imshow(squareform( mat2gray(pdist(data, 'correlation')), 'tomatrix') ); 
colormap('parula'); colorbar;
title('Square Corr pdist');

Wrong Scaling in Output when Full Screen Mode of Matlab where you see the colorbar method is not sufficient for holding relations as proposed in the answer here about How to Control Relative Size of Figures with Colorbar in Matlab?

enter image description here

Right Scaling in Output when Default View

enter image description here


How can you maintain the square view of figures in the Full Screen Mode of Matlab?

1

1 Answers

4
votes

I would simply create a colorbar for the top axes as well and set the visibility to off.

figure;
ax1 = subplot(2,1,1);
ax2 = subplot(2,1,2);

cbar1 = colorbar(ax1);
cbar2 = colorbar(ax2);

set(cbar1, 'Visible', 'off')

enter image description here

The benefit here is that you will get consistent behavior when resizing the figures, etc. because the size and position of the two axes will be rendered in the same way.

The other thing you will need to remember is to keep the axes the same in all aspects. So for example if you have an image in the bottom axes (using imshow), MATLAB by default sets the axes to a square. To get your top plot to also be square you will need to use axis square. Then they will continue to line up.

axis(ax1, 'square')

enter image description here