22Patches are `.Artist`\s with a face color and an edge color.
33"""
44
5- import contextlib
65import functools
76import inspect
87import math
@@ -529,15 +528,15 @@ def get_hatch(self):
529528 """Return the hatching pattern."""
530529 return self ._hatch
531530
532- @ contextlib . contextmanager
533- def _bind_draw_path_function ( self , renderer ):
531+ def _draw_paths_with_artist_properties (
532+ self , renderer , draw_path_args_list ):
534533 """
535534 ``draw()`` helper factored out for sharing with `FancyArrowPatch`.
536535
537- Yields a callable ``dp`` such that calling ``dp(*args, **kwargs)`` is
538- equivalent to calling ``renderer1.draw_path(gc, *args, **kwargs)``
539- where ``renderer1`` and ``gc`` have been suitably set from ``renderer``
540- and the artist's properties .
536+ Configure *renderer* and the associated graphics context *gc*
537+ from the artist properties, then repeatedly call
538+ ``renderer.draw_path(gc, *draw_path_args)`` for each tuple
539+ *draw_path_args* in *draw_path_args_list* .
541540 """
542541
543542 renderer .open_group ('patch' , self .get_gid ())
@@ -571,11 +570,8 @@ def _bind_draw_path_function(self, renderer):
571570 from matplotlib .patheffects import PathEffectRenderer
572571 renderer = PathEffectRenderer (self .get_path_effects (), renderer )
573572
574- # In `with _bind_draw_path_function(renderer) as draw_path: ...`
575- # (in the implementations of `draw()` below), calls to `draw_path(...)`
576- # will occur as if they took place here with `gc` inserted as
577- # additional first argument.
578- yield functools .partial (renderer .draw_path , gc )
573+ for draw_path_args in draw_path_args_list :
574+ renderer .draw_path (gc , * draw_path_args )
579575
580576 gc .restore ()
581577 renderer .close_group ('patch' )
@@ -586,16 +582,17 @@ def draw(self, renderer):
586582 # docstring inherited
587583 if not self .get_visible ():
588584 return
589- with self ._bind_draw_path_function (renderer ) as draw_path :
590- path = self .get_path ()
591- transform = self .get_transform ()
592- tpath = transform .transform_path_non_affine (path )
593- affine = transform .get_affine ()
594- draw_path (tpath , affine ,
595- # Work around a bug in the PDF and SVG renderers, which
596- # do not draw the hatches if the facecolor is fully
597- # transparent, but do if it is None.
598- self ._facecolor if self ._facecolor [3 ] else None )
585+ path = self .get_path ()
586+ transform = self .get_transform ()
587+ tpath = transform .transform_path_non_affine (path )
588+ affine = transform .get_affine ()
589+ self ._draw_paths_with_artist_properties (
590+ renderer ,
591+ [(tpath , affine ,
592+ # Work around a bug in the PDF and SVG renderers, which
593+ # do not draw the hatches if the facecolor is fully
594+ # transparent, but do if it is None.
595+ self ._facecolor if self ._facecolor [3 ] else None )])
599596
600597 def get_path (self ):
601598 """Return the path of this patch."""
@@ -4431,25 +4428,22 @@ def draw(self, renderer):
44314428 if not self .get_visible ():
44324429 return
44334430
4434- with self ._bind_draw_path_function (renderer ) as draw_path :
4435-
4436- # FIXME : dpi_cor is for the dpi-dependency of the linewidth. There
4437- # could be room for improvement. Maybe _get_path_in_displaycoord
4438- # could take a renderer argument, but get_path should be adapted
4439- # too.
4440- self ._dpi_cor = renderer .points_to_pixels (1. )
4441- path , fillable = self ._get_path_in_displaycoord ()
4431+ # FIXME: dpi_cor is for the dpi-dependency of the linewidth. There
4432+ # could be room for improvement. Maybe _get_path_in_displaycoord could
4433+ # take a renderer argument, but get_path should be adapted too.
4434+ self ._dpi_cor = renderer .points_to_pixels (1. )
4435+ path , fillable = self ._get_path_in_displaycoord ()
44424436
4443- if not np .iterable (fillable ):
4444- path = [path ]
4445- fillable = [fillable ]
4437+ if not np .iterable (fillable ):
4438+ path = [path ]
4439+ fillable = [fillable ]
44464440
4447- affine = transforms .IdentityTransform ()
4441+ affine = transforms .IdentityTransform ()
44484442
4449- for p , f in zip ( path , fillable ):
4450- draw_path (
4451- p , affine ,
4452- self . _facecolor if f and self . _facecolor [ 3 ] else None )
4443+ self . _draw_paths_with_artist_properties (
4444+ renderer ,
4445+ [( p , affine , self . _facecolor if f and self . _facecolor [ 3 ] else None )
4446+ for p , f in zip ( path , fillable )] )
44534447
44544448
44554449class ConnectionPatch (FancyArrowPatch ):
0 commit comments