相关疑难解决方法(0)

使用注释在 Matplotlib 中的图例下方放置一个文本框

我希望使用 annotate() 在 Matplotlib 图中显示一些文本,在图例框下方对齐。我已经检查了如何在 matplotlib 中直接在图例下方放置文本框中提出的解决方案并且可以做出适合我的情况的调整,但是添加额外的轴等对于我的情况来说似乎有点过分。我只是希望在图例框的右下角下方放置一个右上角为 20 像素的注释。我还希望保存情节的 PDF 文件。

这是我的代码。

import matplotlib.pyplot as plt
import matplotlib.text

fig, ax = plt.subplots()

ax.plot([5,1], label="Label 1")
ax.plot([3,0], label="Label 2")

legend = ax.legend(loc="upper right")

# Create offset from lower right corner of legend box,
# (1.0,0) is the coordinates of the offset point in the legend coordinate system
offset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))
# Create annotation. Top right corner located -20 pixels below the offset point 
# (lower …
Run Code Online (Sandbox Code Playgroud)

python matplotlib legend

5
推荐指数
0
解决办法
1549
查看次数

标签 统计

legend ×1

matplotlib ×1

python ×1