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

Skip to content

Commit c51103a

Browse files
authored
Merge pull request #28609 from QuLogic/svg-marker-url
svg: Ensure marker-only lines get URLs
2 parents 73a731b + 58d40e3 commit c51103a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ def draw_markers(
715715
self._markers[dictkey] = oid
716716

717717
writer.start('g', **self._get_clip_attrs(gc))
718+
if gc.get_url() is not None:
719+
self.writer.start('a', {'xlink:href': gc.get_url()})
718720
trans_and_flip = self._make_flip_transform(trans)
719721
attrib = {'xlink:href': f'#{oid}'}
720722
clip = (0, 0, self.width*72, self.height*72)
@@ -726,6 +728,8 @@ def draw_markers(
726728
attrib['y'] = _short_float_fmt(y)
727729
attrib['style'] = self._get_style(gc, rgbFace)
728730
writer.element('use', attrib=attrib)
731+
if gc.get_url() is not None:
732+
self.writer.end('a')
729733
writer.end('g')
730734

731735
def draw_path_collection(self, gc, master_transform, paths, all_transforms,

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,17 @@ def test_url():
343343
s.set_urls(['https://example.com/foo', 'https://example.com/bar', None])
344344

345345
# Line2D
346-
p, = plt.plot([1, 3], [6, 5])
346+
p, = plt.plot([2, 3, 4], [4, 5, 6])
347347
p.set_url('https://example.com/baz')
348348

349+
# Line2D markers-only
350+
p, = plt.plot([3, 4, 5], [4, 5, 6], linestyle='none', marker='x')
351+
p.set_url('https://example.com/quux')
352+
349353
b = BytesIO()
350354
fig.savefig(b, format='svg')
351355
b = b.getvalue()
352-
for v in [b'foo', b'bar', b'baz']:
356+
for v in [b'foo', b'bar', b'baz', b'quux']:
353357
assert b'https://example.com/' + v in b
354358

355359

0 commit comments

Comments
 (0)