Python, matplotlib, svg and hyperlinks in text labels

In matplotlib, you can create SVG numbers using hyperlinks .

For example, I can use the method scatterto draw markers so that each individual marker is a hyperlink.

However, some of my markers have text labels that I created using the method text. Can I turn text labels into hyperlinks in any way?


So far, I could achieve the following. First, create a bounding box text label so that the dictionary has bboxa parameter url:

ax.text(x, y, label, bbox=dict(boxstyle=..., url=url))

Then patch matplotlib/backends/backend_svg.py(version 1.1.1) lightly, replacing

self.writer.end('</a>')

with

self.writer.end('a')

. , , ( , , , ).


( , )?

, , matplotlib.

+6
2

.

  • gid :

    ax.text(x, y, label, gid='foo')
    
  • SVG , ; .

  • , , lxml, SVG. <g> id="foo". XML: <g>...</g> <a ...><g>...</g></a>. .

, , ; gid.

0

matplotlib git URL SVG.

@travc, :

url = "https://matplotlib.org/"
txt = plt.text(x, y, url, url=url, bbox = dict(color='w', alpha=0.01, url=url)
+2

All Articles