Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 52e6a12

Browse filesBrowse files
authored
Merge pull request #23571 from anntzer/dpwap
Simplify _bind_draw_path_function.
2 parents 6dee4f5 + 5524dfe commit 52e6a12
Copy full SHA for 52e6a12

File tree

Expand file treeCollapse file tree

1 file changed

+32
-38
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-38
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+32-38Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Patches are `.Artist`\s with a face color and an edge color.
33
"""
44

5-
import contextlib
65
import functools
76
import inspect
87
import 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

44554449
class ConnectionPatch(FancyArrowPatch):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.