Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 302ca01

Browse files
committed
Ensure URLs are stored for plain lines in SVG.
Fixes #17336.
1 parent f13fcbd commit 302ca01

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/matplotlib/lines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ def draw(self, renderer):
756756
if len(tpath.vertices):
757757
gc = renderer.new_gc()
758758
self._set_gc_clip(gc)
759+
gc.set_url(self.get_url())
759760

760761
lc_rgba = mcolors.to_rgba(self._color, self._alpha)
761762
gc.set_foreground(lc_rgba, isRGBA=True)
@@ -782,6 +783,7 @@ def draw(self, renderer):
782783
if self._marker and self._markersize > 0:
783784
gc = renderer.new_gc()
784785
self._set_gc_clip(gc)
786+
gc.set_url(self.get_url())
785787
gc.set_linewidth(self._markeredgewidth)
786788
gc.set_antialiased(self._antialiased)
787789

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,20 @@ def test_url():
219219
# Test that object url appears in output svg.
220220

221221
fig, ax = plt.subplots()
222+
223+
# collections
222224
s = ax.scatter([1, 2, 3], [4, 5, 6])
223225
s.set_urls(['http://example.com/foo', 'http://example.com/bar', None])
224226

227+
# Line2D
228+
p, = plt.plot([1, 3], [6, 5])
229+
p.set_url('http://example.com/baz')
230+
225231
b = BytesIO()
226232
fig.savefig(b, format='svg')
227233
b = b.getvalue()
228-
assert b'http://example.com/foo' in b
229-
assert b'http://example.com/bar' in b
234+
for v in [b'foo', b'bar', b'baz']:
235+
assert b'http://example.com/' + v in b
230236

231237

232238
def test_url_tick():

0 commit comments

Comments
 (0)