【问题标题】:Matlab equivalent to Python's figsizematlab相当于python的figsize
【发布时间】:2019-10-18 08:10:59
【问题描述】:

在 Python 的 matplotlib.pyplot 中,figsize 命令允许您确定图形大小,例如。

from numpy import linspace, sin
import matplotlib.pyplot as plt

x = linspace(-2,2,100)
y = sin(1.5*x)

plt.figure(figsize=(8,5))
plt.plot(x,y)
plt.savefig('myfigure.pdf')
plt.show()

在 Matlab 中是否有一个等效的命令可以做到这一点?这些 old posts 显示了不同的解决方案,但没有一个像 Python 的 figsize 那样干净。

【问题讨论】:

    标签: python matlab matplotlib graph matlab-figure


    【解决方案1】:

    由于你的目标是保存/导出你的身材,所以你必须注意右边的Figure Properties,即:

    我在 Octave 5.1.0 中测试了以下代码,但它应该完全兼容 MATLAB:

    x = linspace(-2, 2, 100);
    y = sin(1.5 * x);
    fig = figure('PaperUnits', 'inches', 'PaperSize', [8 5], 'PaperPosition', [0 0 8 5]);
    plot(x, y);
    saveas(fig, 'myfigure_octave.pdf', 'pdf');
    

    我使用您的代码创建了myfigure_python.pdf。两个导出的图形的大小均为203.2 x 127,0 mm,即8 x 5 inches,看起来非常相似,请参见以下屏幕截图。 myfigure_python.pdf 在左边,myfigure_octave.pdf 在右边:

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 2019-03-06
      • 1970-01-01
      • 2016-02-07
      • 2014-02-23
      • 2023-03-17
      相关资源
      最近更新 更多