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."""
@@ -4415,25 +4412,22 @@ def draw(self, renderer):
44154412 if not self .get_visible ():
44164413 return
44174414
4418- with self ._bind_draw_path_function (renderer ) as draw_path :
4419-
4420- # FIXME : dpi_cor is for the dpi-dependency of the linewidth. There
4421- # could be room for improvement. Maybe _get_path_in_displaycoord
4422- # could take a renderer argument, but get_path should be adapted
4423- # too.
4424- self ._dpi_cor = renderer .points_to_pixels (1. )
4425- path , fillable = self ._get_path_in_displaycoord ()
4415+ # FIXME: dpi_cor is for the dpi-dependency of the linewidth. There
4416+ # could be room for improvement. Maybe _get_path_in_displaycoord could
4417+ # take a renderer argument, but get_path should be adapted too.
4418+ self ._dpi_cor = renderer .points_to_pixels (1. )
4419+ path , fillable = self ._get_path_in_displaycoord ()
44264420
4427- if not np .iterable (fillable ):
4428- path = [path ]
4429- fillable = [fillable ]
4421+ if not np .iterable (fillable ):
4422+ path = [path ]
4423+ fillable = [fillable ]
44304424
4431- affine = transforms .IdentityTransform ()
4425+ affine = transforms .IdentityTransform ()
44324426
4433- for p , f in zip ( path , fillable ):
4434- draw_path (
4435- p , affine ,
4436- self . _facecolor if f and self . _facecolor [ 3 ] else None )
4427+ self . _draw_paths_with_artist_properties (
4428+ renderer ,
4429+ [( p , affine , self . _facecolor if f and self . _facecolor [ 3 ] else None )
4430+ for p , f in zip ( path , fillable )] )
44374431
44384432
44394433class ConnectionPatch (FancyArrowPatch ):
0 commit comments