防止注释显示在图形区域之外

时间:2018-07-11 11:41:26

标签: python python-3.x matplotlib

我用以下代码创建带有注释的散点图:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(12)
plt.scatter(np.random.random(10), np.random.random(10), zorder = 2)
bbox_props = dict(boxstyle = "circle, pad = 10", fc = "w", ec = "k")
plt.annotate("interesting", (0.6, 0.8), bbox = bbox_props, zorder = 1)
plt.show()

示例输出:

enter image description here

如何防止注释显示在图形外部?我进行了搜索,但只能找到相反的情况,人们想在图形外部打印注释/文本/图例。

1 个答案:

答案 0 :(得分:5)

您需要使用clip_on的{​​{1}}参数:

plt.annotate

enter image description here