How to reduce the borders around subplots in matlab AND subaxis doesn't work

孤人 提交于 2019-12-24 09:17:06

问题


I've written a GUI that gives a matlab subplot of varying size and I'm looking for a generic way to squeeze the subplots together. Subaxis works for the vertical spacing, but it doesn't affect the horizontal spacing.

What's the simplest way to squeeze them together? An example of one of the output figures it was produced with the following code in a for loop

 subaxis (1+ceil(max(zindex)/5),5,5+i, 'Padding', 0, 'Margin', 0,'SpacingHoriz',0.0001,'SpacingVert',0.009);

回答1:


It looks like your figure dimensions are way different than the number of plots you have. Subaxis works best if you define your figure size, and you should pick the aspect ratio based on how many plots you have.

in the example you have 13 x 5 subplots, but your figure's aspect ratio is more like 7:13. Hence the vertical plots are close together but there is much horizontal white space.

Before plotting, try defining your figure like:

nRows=13;
nCols=5;
PlotWidth=3;  %This is your Plot width in cm. 
FigW=nCols*FigWidth;
FigH=nRows*FigWidth;   %Note: I'm assuming the plots are square
Figure1=figure(1);clf;
set(Figure1,'PaperUnits','centimeters',...
      'PaperSize',[FigW FigH],...
      'PaperPosition',[0,0,FigW,FigH],...
      'Units','centimeters','Position',[1,9,FigW,FigH]);

and see if your figure spacing looks better. A few notes, if you want to use 'inches' instead of cm that's fine. Also, I don't have any margins on my paper plot (defining the paper-size and paper position is useful for exporting). If you wanted a margin you might try something like:

Mgn=1;
set(Figure1,'PaperUnits','centimeters',...
      'PaperSize',[FigW+2*Mgn FigH+2*Mgn],...
      'PaperPosition',[Mgn,Mgn,FigW,FigH],...
      'Units','centimeters','Position',[1,9,FigW,FigH]);

You can then export using matlab's print command to the format of your choice.



来源:https://stackoverflow.com/questions/13478132/how-to-reduce-the-borders-around-subplots-in-matlab-and-subaxis-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!