@@ -481,6 +481,40 @@ def test_jpeg_alpha():
481
481
assert image .getpixel ((0 , 0 )) == (254 , 0 , 0 )
482
482
483
483
484
+ @cleanup
485
+ def test_minimized_rasterized ():
486
+ # This ensures that the rasterized content in the colorbars is
487
+ # only as thick as the colorbar, and doesn't extend to other parts
488
+ # of the image. See #5814. While the original bug exists only
489
+ # in Postscript, the best way to detect it is to generate SVG
490
+ # and then parse the output to make sure the two colorbar images
491
+ # are the same size.
492
+ from xml .etree import ElementTree
493
+
494
+ np .random .seed (0 )
495
+ data = np .random .rand (10 , 10 )
496
+
497
+ fig , ax = plt .subplots (1 , 2 )
498
+ p1 = ax [0 ].pcolormesh (data )
499
+ p2 = ax [1 ].pcolormesh (data )
500
+
501
+ plt .colorbar (p1 , ax = ax [0 ])
502
+ plt .colorbar (p2 , ax = ax [1 ])
503
+
504
+ buff = io .BytesIO ()
505
+ plt .savefig (buff , format = 'svg' )
506
+
507
+ buff = io .BytesIO (buff .getvalue ())
508
+ tree = ElementTree .parse (buff )
509
+ width = None
510
+ for image in tree .iter ('image' ):
511
+ if width is None :
512
+ width = image ['width' ]
513
+ else :
514
+ if image ['width' ] != width :
515
+ assert False
516
+
517
+
484
518
if __name__ == '__main__' :
485
519
import nose
486
520
nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
0 commit comments