from matplotlib import pyplot as plt
import numpy as np
# generate SVG images instead of PNG
%config InlineBackend.figure_formats = ['svg']
# required for SVG to accept a click on the text area and not just on the text path
"svg.fonttype"] = "none"
plt.rcParams[
plt.figure()1, 2], [4, 6], label="BBC")
plt.scatter([1, 2, 3], [6, 5, 4], label="Google")
plt.scatter([
= {"BBC": 'https://www.bbc.com/news'}
urls
= plt.legend()
leg for ta in leg.texts:
= ta.get_text()
t try:
= urls[t]
url
ta.set_url(url)except KeyError:
pass
# plt.savefig('scatter.svg')
# plt.savefig('scatter.pdf')
This is a demo on what the title says, also see this matplotlib issue. The trick works with SVG and PDF. Try to click on “BBC” in the legend.