2
2
Patches are `.Artist`\s with a face color and an edge color.
3
3
"""
4
4
5
- import contextlib
6
5
import functools
7
6
import inspect
8
7
import math
@@ -529,15 +528,15 @@ def get_hatch(self):
529
528
"""Return the hatching pattern."""
530
529
return self ._hatch
531
530
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 ):
534
533
"""
535
534
``draw()`` helper factored out for sharing with `FancyArrowPatch`.
536
535
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* .
541
540
"""
542
541
543
542
renderer .open_group ('patch' , self .get_gid ())
@@ -571,11 +570,8 @@ def _bind_draw_path_function(self, renderer):
571
570
from matplotlib .patheffects import PathEffectRenderer
572
571
renderer = PathEffectRenderer (self .get_path_effects (), renderer )
573
572
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 )
579
575
580
576
gc .restore ()
581
577
renderer .close_group ('patch' )
@@ -586,16 +582,17 @@ def draw(self, renderer):
586
582
# docstring inherited
587
583
if not self .get_visible ():
588
584
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 )])
599
596
600
597
def get_path (self ):
601
598
"""Return the path of this patch."""
@@ -4415,25 +4412,22 @@ def draw(self, renderer):
4415
4412
if not self .get_visible ():
4416
4413
return
4417
4414
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 ()
4426
4420
4427
- if not np .iterable (fillable ):
4428
- path = [path ]
4429
- fillable = [fillable ]
4421
+ if not np .iterable (fillable ):
4422
+ path = [path ]
4423
+ fillable = [fillable ]
4430
4424
4431
- affine = transforms .IdentityTransform ()
4425
+ affine = transforms .IdentityTransform ()
4432
4426
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 )] )
4437
4431
4438
4432
4439
4433
class ConnectionPatch (FancyArrowPatch ):
0 commit comments