Matlab 相当于 Python 的 figsize
Matlab equivalent to Python's figsize
在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 显示了不同的解决方案,但 none 与 Python 的 figsize
.
一样干净
既然你的目标是saving/exporting你的身材,那么一定要注意正确的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
在右边:
希望对您有所帮助!
在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 显示了不同的解决方案,但 none 与 Python 的 figsize
.
既然你的目标是saving/exporting你的身材,那么一定要注意正确的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
在右边:
希望对您有所帮助!