1717from matplotlib .backend_bases import RendererBase , GraphicsContextBase ,\
1818 FigureManagerBase , FigureCanvasBase
1919from matplotlib .backends .backend_mixed import MixedModeRenderer
20- from matplotlib .cbook import is_string_like , is_writable_file_like , maxdict
20+ from matplotlib .cbook import (is_string_like , is_writable_file_like , maxdict ,
21+ sorted_iteritems , sorted_itervalues )
2122from matplotlib .colors import rgb2hex
2223from matplotlib .figure import Figure
2324from matplotlib .font_manager import findfont , FontProperties , get_font
@@ -358,7 +359,7 @@ def _write_hatches(self):
358359 HATCH_SIZE = 72
359360 writer = self .writer
360361 writer .start ('defs' )
361- for ((path , face , stroke ), oid ) in six . itervalues (self ._hatchd ):
362+ for ((path , face , stroke ), oid ) in sorted_itervalues (self ._hatchd ):
362363 writer .start (
363364 'pattern' ,
364365 id = oid ,
@@ -469,7 +470,7 @@ def _write_clips(self):
469470 return
470471 writer = self .writer
471472 writer .start ('defs' )
472- for clip , oid in six . itervalues (self ._clipd ):
473+ for clip , oid in sorted_itervalues (self ._clipd ):
473474 writer .start ('clipPath' , id = oid )
474475 if len (clip ) == 2 :
475476 clippath , clippath_trans = clip
@@ -488,7 +489,7 @@ def _write_svgfonts(self):
488489
489490 writer = self .writer
490491 writer .start ('defs' )
491- for font_fname , chars in six . iteritems (self ._fonts ):
492+ for font_fname , chars in sorted_iteritems (self ._fonts ):
492493 font = get_font (font_fname )
493494 font .set_size (72 , 72 )
494495 sfnt = font .get_sfnt ()
@@ -829,7 +830,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
829830 if rcParams ['svg.image_inline' ]:
830831 bytesio = io .BytesIO ()
831832 _png .write_png (np .array (im )[::- 1 ], bytesio )
832- oid = oid or self ._make_id ('image' , bytesio )
833+ oid = oid or self ._make_id ('image' , bytesio . getvalue () )
833834 attrib ['xlink:href' ] = (
834835 "data:image/png;base64,\n " +
835836 base64 .b64encode (bytesio .getvalue ()).decode ('ascii' ))
@@ -917,7 +918,7 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
917918
918919 if glyph_map_new :
919920 writer .start ('defs' )
920- for char_id , glyph_path in six . iteritems (glyph_map_new ):
921+ for char_id , glyph_path in sorted_iteritems (glyph_map_new ):
921922 path = Path (* glyph_path )
922923 path_data = self ._convert_path (path , simplify = False )
923924 writer .element ('path' , id = char_id , d = path_data )
@@ -960,7 +961,7 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
960961 # used.
961962 if glyph_map_new :
962963 writer .start ('defs' )
963- for char_id , glyph_path in six . iteritems (glyph_map_new ):
964+ for char_id , glyph_path in sorted_iteritems (glyph_map_new ):
964965 char_id = self ._adjust_char_id (char_id )
965966 # Some characters are blank
966967 if not len (glyph_path [0 ]):
@@ -1104,7 +1105,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
11041105 fontset = self ._fonts .setdefault (font .fname , set ())
11051106 fontset .add (thetext )
11061107
1107- for style , chars in six . iteritems (spans ):
1108+ for style , chars in sorted_iteritems (spans ):
11081109 chars .sort ()
11091110
11101111 same_y = True
0 commit comments