在你的代码之后运行以下代码。
imgwidth = max(1, ceil(max(x) - min(x)));
imgheight = max(1, ceil(max(y) - min(y)));
ax = gca;
ax.Visible = 'off';
ax.XTickMode = 'manual';
ax.YTickMode = 'manual';
ax.ZTickMode = 'manual';
ax.XLimMode = 'manual';
ax.YLimMode = 'manual';
ax.ZLimMode = 'manual';
ax.Position = ax.OuterPosition;
af = gcf;
figpos = getpixelposition(af);
resolution=get(0, 'ScreenPixelsPerInch');
set(af, 'paperunits','inches', ....
'papersize',[imgwidth imgheight]/resolution, ....
'paperposition',[0 0 [imgwidth imgheight]/resolution]);
print(af,'out.png','-dpng',['-r',num2str(resolution)],'-opengl')
完成的事情:
-
-
关闭轴和记号。
-
最小化/删除实际内容周围的填充空间。
-
未完成的事情:
Mathworks - Save Figure at Specific Size and Resolution
MATLAB Central - saving a figure at a set resolution
Mathworks -
print
Mathworks - Save Figure with Minimal White Space