I\'ve created a plot in Python using matplotlib. After annotating each line, I\'d like to make the label a hyperlink (or alternatively, make the line itself a hyperlink). Th
Adding a hyperlink makes sense when e.g. using an SVG file.
The url property works in newer matplotlib versions:
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'))
For example, in a Jupyter notebook, which runs in a browser anyways, one could display an SVG with hyperlinks like this:
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'))
In the figure produced this way you may click on the link and be directed to matplotlib.org.