在双 y 图中拉伸图形大小
Stretching figure size in a double-y plot
我正在尝试学习如何在显示 (plt.show()
) 和保存 (plt.savefig
) 时拉伸绘图的宽度。
更准确地说,该图有两个 y 轴,我写如下:
fig , ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(x,y)
ax2.plot(x,y2)
plt.show()
现在的问题是,如何指定绘图的大小,例如,我们如何拉伸 width/height?
当使用 plt.show()
并出现绘图时,我可以手动取一个角并根据需要调整框的大小,但手动自定义的大小不会是保存的大小。
您可以通过figsize=(width, height)
设置图形大小比例
import matplotlib.pyplot as plt
x = [1, 2, 3] # dummy data
y = [4, 5, 6]
y2 = [16, 25, 36]
fig , ax1 = plt.subplots(figsize=(7, 2)) # <-- aspect wider than high
ax2 = ax1.twinx()
ax1.plot(x,y)
ax2.plot(x,y2)
plt.show()
我正在尝试学习如何在显示 (plt.show()
) 和保存 (plt.savefig
) 时拉伸绘图的宽度。
更准确地说,该图有两个 y 轴,我写如下:
fig , ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(x,y)
ax2.plot(x,y2)
plt.show()
现在的问题是,如何指定绘图的大小,例如,我们如何拉伸 width/height?
当使用 plt.show()
并出现绘图时,我可以手动取一个角并根据需要调整框的大小,但手动自定义的大小不会是保存的大小。
您可以通过figsize=(width, height)
import matplotlib.pyplot as plt
x = [1, 2, 3] # dummy data
y = [4, 5, 6]
y2 = [16, 25, 36]
fig , ax1 = plt.subplots(figsize=(7, 2)) # <-- aspect wider than high
ax2 = ax1.twinx()
ax1.plot(x,y)
ax2.plot(x,y2)
plt.show()