Problem
tl;dr It would be great if URLs could be assigned to legend entries, so that a click on the legend entry in a SVG image brings you to the URL.
I am generating plots such as this one:

(Source: https://github.com/crdb-project/tutorial/blob/master/gallery.ipynb)
which includes a lot of data from other papers. The table in gray gives credit to those papers, which are listed via a key that is understood in the field (it is a key from this database https://ui.adsabs.harvard.edu, but that is an irrelevant detail).
It would be super nice if the entries in that table were clickable and would bring you to a page with that paper. I have the URLs, so I only need a way to make clickable legend entries, because this table is actually generated with a matplotlib legend object (this is also a detail, I could have programmed a proper table using VPacker, HPacker, and TextArea, but just misusing a legend was the simplest option).
Some searching made me aware of this feature here:
https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html
which works great to assign URLs to points. But I cannot get it to work for legend entries. Specifically, I tried this code:
from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure()
plt.scatter([1, 2], [4, 6], label="BBC")
plt.scatter([1, 2, 3], [6, 5, 4], label="Google")
leg = plt.legend()
for entry in leg.get_children()[0].get_children()[1].get_children()[0].get_children():
da, ta = entry.get_children()
t = ta.get_text()
if t == "BBC":
url = 'https://www.bbc.com/news'
ta.set_url(url)
da.set_url(url)
entry.set_url(url)
fig.savefig('scatter.svg')
Problem
tl;dr It would be great if URLs could be assigned to legend entries, so that a click on the legend entry in a SVG image brings you to the URL.
I am generating plots such as this one:
(Source: https://github.com/crdb-project/tutorial/blob/master/gallery.ipynb)
which includes a lot of data from other papers. The table in gray gives credit to those papers, which are listed via a key that is understood in the field (it is a key from this database https://ui.adsabs.harvard.edu, but that is an irrelevant detail).
It would be super nice if the entries in that table were clickable and would bring you to a page with that paper. I have the URLs, so I only need a way to make clickable legend entries, because this table is actually generated with a matplotlib legend object (this is also a detail, I could have programmed a proper table using VPacker, HPacker, and TextArea, but just misusing a legend was the simplest option).
Some searching made me aware of this feature here:
https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html
which works great to assign URLs to points. But I cannot get it to work for legend entries. Specifically, I tried this code: