3030import matplotlib .ticker as mticker
3131import matplotlib .transforms as mtransforms
3232
33+ from operator import itemgetter
34+
3335iterable = cbook .iterable
3436is_string_like = cbook .is_string_like
3537is_sequence_of_strings = cbook .is_sequence_of_strings
@@ -1698,11 +1700,22 @@ def draw(self, renderer=None, inframe=False):
16981700 artists .extend (self .spines .itervalues ())
16991701
17001702
1703+
17011704 dsu = [ (a .zorder , a ) for a in artists
17021705 if not a .get_animated () ]
1703- dsu .sort (key = lambda x : x [0 ])
17041706
17051707
1708+ # add images to dsu if the backend support compositing.
1709+ # otherwise, does the manaul compositing without adding images to dsu.
1710+ if len (self .images )<= 1 or renderer .option_image_nocomposite ():
1711+ dsu .extend ([(im .zorder , im ) for im in self .images ])
1712+ _do_composite = False
1713+ else :
1714+ _do_composite = True
1715+
1716+
1717+ dsu .sort (key = itemgetter (0 ))
1718+
17061719 # rasterize artists with negative zorder
17071720 # if the minimum zorder is negative, start rasterization
17081721 rasterization_zorder = self ._rasterization_zorder
@@ -1719,11 +1732,7 @@ def draw(self, renderer=None, inframe=False):
17191732 if self .axison and self ._frameon :
17201733 self .patch .draw (renderer )
17211734
1722- if len (self .images )<= 1 or renderer .option_image_nocomposite ():
1723- for im in self .images :
1724- dsu .append ( (im .zorder , im ) )
1725- dsu .sort (key = lambda x : x [0 ]) # re-sort with images now
1726- else :
1735+ if _do_composite :
17271736 # make a composite image blending alpha
17281737 # list of (mimage.Image, ox, oy)
17291738
0 commit comments