我使用matplotlib库来绘制Python中的数据图。在我的图中,我还有一些文本来区分数据。问题是文本超出了图形窗口的边界。是否可以使图形边框在相应位置截断文本,并且只有当我在图中移动时,其余部分的文本才会可见(但仅在图区内)。我使用text()函数来显示文本。
[编辑:]
代码如下:
[编辑:]
代码如下:
fig = plt.figure()
ax = fig.add_subplot(111)
# ...
txt = ax.text(x, y, n, fontsize=10)
txt.set_clip_on(False) # I added this due to the answer from tcaswell