【发布时间】:2015-04-22 16:09:40
【问题描述】:
我正在使用 ipython notebook 绘制一个带有 2 个 ylabels 的图,当在 notebook 中可视化时,图像看起来不错。
这是我的做法:
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots()
plt.title('TITLE')
plt.xlabel('X')
plt.plot(x, y1, '-', color='blue', label='SNR')
ax1.set_ylabel('y1', color='blue')
for tl in ax1.get_yticklabels():
tl.set_color('blue')
ax2 = ax1.twinx()
plt.plot(x, y2, '--', color='red', label='Ngal')
ax2.set_ylabel('y2', color='red')
for tl in ax2.get_yticklabels():
tl.set_color('red')
问题是当我尝试使用命令保存时
plt.savefig('output.png', dpi=300)
因为输出将是在右侧切割的图像:如果正确的数字很大,基本上我看不到正确的 ylabel。
【问题讨论】:
-
在
savefig命令之前尝试fig.tight_layout()
标签: python matplotlib ipython ipython-notebook