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."""
@@ -4431,25 +4428,22 @@ def draw(self, renderer):
4431
4428
if not self .get_visible ():
4432
4429
return
4433
4430
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 ()
4442
4436
4443
- if not np .iterable (fillable ):
4444
- path = [path ]
4445
- fillable = [fillable ]
4437
+ if not np .iterable (fillable ):
4438
+ path = [path ]
4439
+ fillable = [fillable ]
4446
4440
4447
- affine = transforms .IdentityTransform ()
4441
+ affine = transforms .IdentityTransform ()
4448
4442
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 )] )
4453
4447
4454
4448
4455
4449
class ConnectionPatch (FancyArrowPatch ):
0 commit comments