# [Matlab] 如何将axes填充整个Figure

## 程序演示

for i = 1:4
% plot a figure
figure;
x = normrnd(0, 3, [100, 3]);
hist(x);
legend({'$C_1$', '$C_2$', '$C_3$'}, 'Interpreter', 'latex', 'Location', 'NorthEast');
xlabel('\textbf{Variabel} $x$', 'Interpreter', 'latex');
ylabel('\textbf{Count}', 'Interpreter', 'latex');
title(['Figure ', num2str(i)]);

% specify figure size
af = gcf;
af.Position(3) = af.Position(3)*0.7;
af.Position(4) = af.Position(4)*0.5;

% expand axes to fill figure
ax = gca;
outerpos = ax.OuterPosition;
ti = ax.TightInset;
left = outerpos(1) + ti(1);
bottom = outerpos(2) + ti(2);
ax_width = outerpos(3) - ti(1) - ti(3);
ax_height = outerpos(4) - ti(2) - ti(4);
ax.Position = [left bottom ax_width ax_height];

% Specify Page Size
af.PaperPositionMode = 'auto';
fig_pos = af.PaperPosition;
af.PaperSize = [fig_pos(3) fig_pos(4)];

% save the figure
print(af, ['Figure_', num2str(i), '.png'], '-dpng');
end

• 本文已收录于以下专栏：

举报原因： 您举报文章：[Matlab] 如何将axes填充整个Figure 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)