@@ -214,3 +214,48 @@ def test_savefig_tight():
214214 # Check that the draw-disabled renderer correctly disables open/close_group
215215 # as well.
216216 plt .savefig (BytesIO (), format = "svgz" , bbox_inches = "tight" )
217+
218+
219+ def test_url ():
220+ # Test that object url appears in output svg.
221+
222+ fig , ax = plt .subplots ()
223+
224+ # collections
225+ s = ax .scatter ([1 , 2 , 3 ], [4 , 5 , 6 ])
226+ s .set_urls (['http://example.com/foo' , 'http://example.com/bar' , None ])
227+
228+ # Line2D
229+ p , = plt .plot ([1 , 3 ], [6 , 5 ])
230+ p .set_url ('http://example.com/baz' )
231+
232+ b = BytesIO ()
233+ fig .savefig (b , format = 'svg' )
234+ b = b .getvalue ()
235+ for v in [b'foo' , b'bar' , b'baz' ]:
236+ assert b'http://example.com/' + v in b
237+
238+
239+ def test_url_tick ():
240+ fig1 , ax = plt .subplots ()
241+ ax .scatter ([1 , 2 , 3 ], [4 , 5 , 6 ])
242+ for i , tick in enumerate (ax .yaxis .get_major_ticks ()):
243+ tick .set_url (f'http://example.com/{ i } ' )
244+
245+ fig2 , ax = plt .subplots ()
246+ ax .scatter ([1 , 2 , 3 ], [4 , 5 , 6 ])
247+ for i , tick in enumerate (ax .yaxis .get_major_ticks ()):
248+ tick .label1 .set_url (f'http://example.com/{ i } ' )
249+ tick .label2 .set_url (f'http://example.com/{ i } ' )
250+
251+ b1 = BytesIO ()
252+ fig1 .savefig (b1 , format = 'svg' )
253+ b1 = b1 .getvalue ()
254+
255+ b2 = BytesIO ()
256+ fig2 .savefig (b2 , format = 'svg' )
257+ b2 = b2 .getvalue ()
258+
259+ for i in range (len (ax .yaxis .get_major_ticks ())):
260+ assert f'http://example.com/{ i } ' .encode ('ascii' ) in b1
261+ assert b1 == b2
0 commit comments