添加超链接是有意义的,例如使用 SVG 文件。
url 属性适用于较新的 matplotlib 版本:
text = plt.annotate("Link", xy=(2,5), xytext=(2.2,5.5),
url='http://matplotlib.org',
bbox=dict(color='w', alpha=1e-6, url='http://matplotlib.org'))
例如,在浏览器中运行的 Jupyter 笔记本中,可以显示带有如下超链接的 SVG:
import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats
set_matplotlib_formats("svg")
fig, ax = plt.subplots()
ax.scatter([1, 2, 3], [4, 5, 6])
text = ax.annotate("Link", xy=(2,5), xytext=(2.2,5.5),
url='http://matplotlib.org',
bbox=dict(color='w', alpha=1e-6, url='http://matplotlib.org'))
在以这种方式生成的图中,您可以单击链接并被定向到 matplotlib.org。