如何在Matlab中设置图形尺寸而不设置它的位置?

问题描述 投票:-1回答:2

在Python中,我可以将大小传递给figure指令:

figure(figsize=(8,6))

在Matlab中我没有看到这种能力。我有复杂的建议

set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperPosition', [2 1 4 2]);

其中包括设置大小和位置。

如何在Matlab中以最简单的方式设置尺寸?

matlab plot
2个回答
4
投票

这应该工作:

set(gcf, 'Position', get(gcf,'Position').*[1 1 0 0] + [0 0 newWidth newHeight]);

如果您的MATLAB是R2014b或更新,您还可以:

hF = gcf;
hF.Position(3:4) = [newWidth newHeight];

1
投票

据我所知,没有可能只设置大小,但你可以获得默认的位置/大小,并将其用作解决方法。要这样做,只需写下:

figPos = get(0,'defaultfigureposition');
width = 400;
height = 400;
figure('Position', [figPos(1), figPos(2), width, height]);

这将仅在初始化图形时设置大小。对于已初始化的数字,请使用图中的handle元素gcf

set(gcf, 'Position', [values])

如果要将该大小设置为默认值,请将set用于属性'defaultfigureposition'

set(0, 'defaultfigureposition', [values]);
© www.soinside.com 2019 - 2024. All rights reserved.