Adjusting size of plot in Matlab so that graph does not get cut off by edge of plot window

99封情书 提交于 2019-12-01 01:05:12

Try to set the OuterPosition of the plot.

set(gca,'OuterPosition',[0.2 0.2 0.8 0.4]);

The image below shows the difference between the two:

Here is the relevant MathWorks help page.

Andrey has the simplest answer, but alternatively (and for the long term) you can go to the file exchange and download subaxis.m, which replaces subplot, and is superb for even single axes plots (you can define properties like LeftMargin and RightMargin and PaddingTop and PaddingBottom)

http://www.mathworks.com/matlabcentral/fileexchange/3696-subaxis-subplot

The following document (How to produce figures with Matlab that have the right dimensions when printed) provides some example code that can be used to resize the plot in the proper fashion.

The following code was used:

point = num(:, 1);
depth = num(:, 2);

hfig = plot(point, depth, '-s', 'Color', 'k', 'MarkerFaceColor', 'k', 'MarkerEdgeColor', 'k', 'MarkerSize', 10);
set(gca, 'LineWidth', axis_size);
set(gca,'FontSize', ticksize, 'FontName', fontname);
set(gcf,'PaperUnits','centimeters')
xSize = 30; ySize = 5;
xLeft = (21-xSize)/2; yTop = (30-ySize)/2;
set(gcf,'PaperPosition',[xLeft yTop xSize ySize])
set(gcf,'Position',[300 600 xSize*50 ySize*50])

xlabel('Point Number');
ylabel('Depth (cm)');  

Here is a picture of the result. This looks similar to the one that I posted in my question above. I don't know if this is dependent on monitor size and/or screen resolution.

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