@@ -443,6 +443,12 @@ def draw(self, renderer):
443443 # iterate over all paths and draw them one by one.
444444 hatchcolors_arg_supported = False
445445
446+ # If the hatchcolors argument is not needed or not passed
447+ # then we can skip the iteration over paths in case the
448+ # argument is not supported by the renderer.
449+ hatchcolors_not_needed = (self .get_hatch () is None or
450+ self ._original_hatchcolor is None )
451+
446452 if self ._gapcolor is not None :
447453 # First draw paths within the gaps.
448454 ipaths , ilinestyles = self ._get_inverse_paths_linestyles ()
@@ -455,16 +461,21 @@ def draw(self, renderer):
455461 self .get_transforms (), * args ,
456462 hatchcolors = self .get_hatchcolor ())
457463 else :
458- path_ids = renderer ._iter_collection_raw_paths (
459- transform .frozen (), ipaths , self .get_transforms ())
460- for xo , yo , path_id , gc0 , rgbFace in renderer ._iter_collection (
461- gc , list (path_ids ), * args , hatchcolors = self .get_hatchcolor (),
462- ):
463- path , transform = path_id
464- if xo != 0 or yo != 0 :
465- transform = transform .frozen ()
466- transform .translate (xo , yo )
467- renderer .draw_path (gc0 , path , transform , rgbFace )
464+ if hatchcolors_not_needed :
465+ renderer .draw_path_collection (gc , transform .frozen (), ipaths ,
466+ self .get_transforms (), * args )
467+ else :
468+ path_ids = renderer ._iter_collection_raw_paths (
469+ transform .frozen (), ipaths , self .get_transforms ())
470+ for xo , yo , path_id , gc0 , rgbFace in renderer ._iter_collection (
471+ gc , list (path_ids ), * args ,
472+ hatchcolors = self .get_hatchcolor (),
473+ ):
474+ path , transform = path_id
475+ if xo != 0 or yo != 0 :
476+ transform = transform .frozen ()
477+ transform .translate (xo , yo )
478+ renderer .draw_path (gc0 , path , transform , rgbFace )
468479
469480 args = [offsets , offset_trf , self .get_facecolor (), self .get_edgecolor (),
470481 self ._linewidths , self ._linestyles , self ._antialiaseds , self ._urls ,
@@ -475,16 +486,20 @@ def draw(self, renderer):
475486 self .get_transforms (), * args ,
476487 hatchcolors = self .get_hatchcolor ())
477488 else :
478- path_ids = renderer ._iter_collection_raw_paths (
479- transform .frozen (), paths , self .get_transforms ())
480- for xo , yo , path_id , gc0 , rgbFace in renderer ._iter_collection (
481- gc , list (path_ids ), * args , hatchcolors = self .get_hatchcolor (),
482- ):
483- path , transform = path_id
484- if xo != 0 or yo != 0 :
485- transform = transform .frozen ()
486- transform .translate (xo , yo )
487- renderer .draw_path (gc0 , path , transform , rgbFace )
489+ if hatchcolors_not_needed :
490+ renderer .draw_path_collection (gc , transform .frozen (), paths ,
491+ self .get_transforms (), * args )
492+ else :
493+ path_ids = renderer ._iter_collection_raw_paths (
494+ transform .frozen (), paths , self .get_transforms ())
495+ for xo , yo , path_id , gc0 , rgbFace in renderer ._iter_collection (
496+ gc , list (path_ids ), * args , hatchcolors = self .get_hatchcolor (),
497+ ):
498+ path , transform = path_id
499+ if xo != 0 or yo != 0 :
500+ transform = transform .frozen ()
501+ transform .translate (xo , yo )
502+ renderer .draw_path (gc0 , path , transform , rgbFace )
488503
489504 gc .restore ()
490505 renderer .close_group (self .__class__ .__name__ )
0 commit comments