@@ -775,6 +775,67 @@ def get_color(self):
775775 return self ._edgecolors
776776 get_colors = get_color # for compatibility with old versions
777777
778+ class PatchCollection (Collection ):
779+ """
780+ A generic collection of patches.
781+
782+ This makes it easier to assign a color map to a heterogeneous
783+ collection of patches.
784+
785+ This also may improve plotting speed, since PatchCollection will
786+ draw faster than a large number of patches.
787+ """
788+
789+ def __init__ (self , patches , match_original = False , ** kwargs ):
790+ """
791+ *patches*
792+ a sequence of Patch objects. This list may include
793+ a heterogeneous assortment of different patch types.
794+
795+ *match_original* If True, use the colors and linewidths of the
796+ original patches. If False, new colors may be assigned by
797+ providing the standard collection arguments, facecolor,
798+ edgecolor, linewidths, norm or cmap.
799+
800+ If any of *edgecolors*, *facecolors*, *linewidths*,
801+ *antialiaseds* are None, they default to their
802+ :data:`matplotlib.rcParams` patch setting, in sequence form.
803+
804+ The use of :class:`~matplotlib.cm.ScalarMappable` is optional.
805+ If the :class:`~matplotlib.cm.ScalarMappable` matrix _A is not
806+ None (ie a call to set_array has been made), at draw time a
807+ call to scalar mappable will be made to set the face colors.
808+ """
809+
810+ if match_original :
811+ def determine_facecolor (patch ):
812+ if patch .fill ():
813+ return patch .get_facecolor ()
814+ return [0 , 0 , 0 , 0 ]
815+
816+ facecolors = [determine_facecolor (p ) for p in patches ]
817+ edgecolors = [p .get_edgecolor () for p in patches ]
818+ linewidths = [p .get_linewidths () for p in patches ]
819+ antialiaseds = [p .get_antialiased () for p in patches ]
820+
821+ Collection .__init__ (
822+ self ,
823+ edgecolors = edgecolors ,
824+ facecolors = facecolors ,
825+ linewidths = linewidths ,
826+ linestyles = 'solid' ,
827+ antialiaseds = antialiaseds )
828+ else :
829+ Collection .__init__ (self , ** kwargs )
830+
831+ paths = [p .get_transform ().transform_path (p .get_path ())
832+ for p in patches ]
833+
834+ self ._paths = paths
835+
836+ def get_paths (self ):
837+ return self ._paths
838+
778839
779840artist .kwdocd ['Collection' ] = patchstr = artist .kwdoc (Collection )
780841for k in ('QuadMesh' , 'PolyCollection' , 'BrokenBarHCollection' , 'RegularPolyCollection' ,
0 commit comments