Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ def set_label2(self, s):
self.label2.set_text(s)
self.stale = True

def set_url(self, url):
"""
Set the url of label1 and label2.

Parameters
----------
url : str
"""
super().set_url(url)
self.label1.set_url(url)
self.label2.set_url(url)
self.stale = True

def _set_artist_props(self, a):
a.set_figure(self.figure)

Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ def draw(self, renderer):
if len(tpath.vertices):
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_url(self.get_url())

lc_rgba = mcolors.to_rgba(self._color, self._alpha)
gc.set_foreground(lc_rgba, isRGBA=True)
Expand All @@ -787,6 +788,7 @@ def draw(self, renderer):
if self._marker and self._markersize > 0:
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_url(self.get_url())
gc.set_linewidth(self._markeredgewidth)
gc.set_antialiased(self._antialiased)

Expand Down
45 changes: 45 additions & 0 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,48 @@ def test_savefig_tight():
# Check that the draw-disabled renderer correctly disables open/close_group
# as well.
plt.savefig(BytesIO(), format="svgz", bbox_inches="tight")


def test_url():
# Test that object url appears in output svg.

fig, ax = plt.subplots()

# collections
s = ax.scatter([1, 2, 3], [4, 5, 6])
s.set_urls(['http://example.com/foo', 'http://example.com/bar', None])

# Line2D
p, = plt.plot([1, 3], [6, 5])
p.set_url('http://example.com/baz')

b = BytesIO()
fig.savefig(b, format='svg')
b = b.getvalue()
for v in [b'foo', b'bar', b'baz']:
assert b'http://example.com/' + v in b


def test_url_tick():
fig1, ax = plt.subplots()
ax.scatter([1, 2, 3], [4, 5, 6])
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
tick.set_url(f'http://example.com/{i}')

fig2, ax = plt.subplots()
ax.scatter([1, 2, 3], [4, 5, 6])
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
tick.label1.set_url(f'http://example.com/{i}')
tick.label2.set_url(f'http://example.com/{i}')

b1 = BytesIO()
fig1.savefig(b1, format='svg')
b1 = b1.getvalue()

b2 = BytesIO()
fig2.savefig(b2, format='svg')
b2 = b2.getvalue()

for i in range(len(ax.yaxis.get_major_ticks())):
assert f'http://example.com/{i}'.encode('ascii') in b1
assert b1 == b2