【发布时间】:2015-07-06 05:47:40
【问题描述】:
我正在使用 matplotlib 在使用注释时绘制一些图形。我遇到的问题是注释(在绘图区域之外)从保存的图片中被切断,如下图所示。
下图就是我想要的:
有人知道如何解决这个问题吗?我注意到人们建议在 rcParams 中使用 plt.tight_plot() 或 fig.autolayout,但这似乎不起作用。下面是生成图形的代码。
fig, ax = plt.subplots()
ax.set_xlim([-0.02,1.1])
ax.set_ylim([-0.02,1.1])
ax.plot([0,0,0,0.5,0.5,0.5,1,1,1], [0,0.5,1,0,0.5,1,0,0.5,1], 'go')
ax.annotate("Digit 2",
xy=(0.5, -0.1), xycoords='data',
xytext=(0.5, -0.3), textcoords='data',
arrowprops=dict(arrowstyle="->",
connectionstyle="arc3"),
annotation_clip=False,
fontsize = 12,
ha='center',
)
ax.annotate("Level 2",
xy=(-0.1, 1), xycoords='data',
xytext=(-0.35, 1), textcoords='data',
arrowprops=dict(arrowstyle="->",
connectionstyle="arc3"),
annotation_clip=False,
fontsize = 12,
va='center',
)
plt.savefig('sample.png', dpi = 300)
【问题讨论】:
标签: python matplotlib