How to keep the subplot sizes unchanged after putting a colorbar

前端 未结 2 1264
渐次进展
渐次进展 2021-02-05 23:41

Let us say we have a 1-by-2 subplot and we plot some graphics inside as follows:

subplot(1,2,1)
surf(peaks(20))

subplot(1,2,2)
surf(peaks(20))

2条回答
  •  别跟我提以往
    2021-02-05 23:59

    This is just what I was looking for. After implementing Vidar's automatic solution I came up with a simplification. Get the position of the far right axes BEFORE adding the colorbar, and then just reset the squeezed position to the original:

    f1=figure(1);clf;
    s1=subplot(1,2,1);
    surf(peaks(20));
    
    s2=subplot(1,2,2);
    surf(peaks(20));
    s2Pos = get(s2,'position');
    
    hb = colorbar('location','eastoutside');
    set(s2,'position',s2Pos);
    

提交回复
热议问题