root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.64k stars 1.26k forks source link

Enable embedding hyperlinks in TLegend #16512

Open vepadulano opened 4 days ago

vepadulano commented 4 days ago

Explain what you would like to see improved and how.

I have a simple snippet which produces a plot (in PDF or SVG) where the text items in the legend are clickable hyperlinks:

from matplotlib import pyplot as plt
plt.rcParams['svg.fonttype'] = 'none'
fig = plt.figure()
plt.scatter([1], [2], label="CERN")
plt.scatter([1], [2.25], label="ROOT")
leg = plt.legend()
for ta in leg.texts:
    t = ta.get_text()
    if t == "CERN":
        url = 'https://home.cern'
        ta.set_url(url)
    elif t == "ROOT":
        url = 'https://root.cern'
        ta.set_url(url)

fig.savefig('scatter.svg')
fig.savefig('scatter.pdf')

Can be run with python repro.py and saves both SVG and PDF files with the clickable links in the legend.

It would be nice to have the same feature also for TLegend. I have taken a look at TLink but despite what the docs hint at, that cannot be used to show hyperlinks, rather only links between different graphical components of the same canvas/browser.

ROOT version

Any

Installation method

Any

Operating system

Any

Additional context

No response

couet commented 1 day ago

@vepadulano can you post the 2 files generated by your macro ?