Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fee895b

Browse files
committed
Refactor draw_path_collection to make hatchcolors a keyword-only argument
1 parent d2b6268 commit fee895b

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path,
208208
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
209209
offsets, offset_trans, facecolors, edgecolors,
210210
linewidths, linestyles, antialiaseds, urls,
211-
offset_position, hatchcolors=None):
211+
offset_position, *, hatchcolors=None):
212212
"""
213213
Draw a collection of *paths*.
214214
@@ -277,7 +277,8 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
277277

278278
return self.draw_path_collection(
279279
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
280-
edgecolors, linewidths, [], [antialiased], [None], 'screen', hatchcolors)
280+
edgecolors, linewidths, [], [antialiased], [None], 'screen',
281+
hatchcolors=hatchcolors)
281282

282283
def draw_gouraud_triangles(self, gc, triangles_array, colors_array,
283284
transform):

lib/matplotlib/backend_bases.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class RendererBase:
6363
antialiaseds: bool | Sequence[bool],
6464
urls: str | Sequence[str],
6565
offset_position: Any,
66+
*,
6667
hatchcolors: ColorType | Sequence[ColorType] | None = None,
6768
) -> None: ...
6869
def draw_quad_mesh(

lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
20302030
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
20312031
offsets, offset_trans, facecolors, edgecolors,
20322032
linewidths, linestyles, antialiaseds, urls,
2033-
offset_position, hatchcolors=None):
2033+
offset_position, *, hatchcolors=None):
20342034
# We can only reuse the objects if the presence of fill and
20352035
# stroke (and the amount of alpha for each) is the same for
20362036
# all of them
@@ -2075,7 +2075,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
20752075
self, gc, master_transform, paths, all_transforms,
20762076
offsets, offset_trans, facecolors, edgecolors,
20772077
linewidths, linestyles, antialiaseds, urls,
2078-
offset_position, hatchcolors)
2078+
offset_position, hatchcolors=hatchcolors)
20792079

20802080
padding = np.max(linewidths)
20812081
path_codes = []

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def draw_markers(
674674
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
675675
offsets, offset_trans, facecolors, edgecolors,
676676
linewidths, linestyles, antialiaseds, urls,
677-
offset_position, hatchcolors=None):
677+
offset_position, *, hatchcolors=None):
678678
if hatchcolors is None:
679679
hatchcolors = []
680680
# Is the optimization worth it? Rough calculation:
@@ -692,7 +692,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
692692
self, gc, master_transform, paths, all_transforms,
693693
offsets, offset_trans, facecolors, edgecolors,
694694
linewidths, linestyles, antialiaseds, urls,
695-
offset_position, hatchcolors)
695+
offset_position, hatchcolors=hatchcolors)
696696

697697
path_codes = []
698698
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def draw_markers(
736736
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
737737
offsets, offset_trans, facecolors, edgecolors,
738738
linewidths, linestyles, antialiaseds, urls,
739-
offset_position, hatchcolors=None):
739+
offset_position, *, hatchcolors=None):
740740
if hatchcolors is None:
741741
hatchcolors = []
742742
# Is the optimization worth it? Rough calculation:
@@ -754,7 +754,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
754754
gc, master_transform, paths, all_transforms,
755755
offsets, offset_trans, facecolors, edgecolors,
756756
linewidths, linestyles, antialiaseds, urls,
757-
offset_position, hatchcolors)
757+
offset_position, hatchcolors=hatchcolors)
758758

759759
writer = self.writer
760760
path_codes = []

lib/matplotlib/collections.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def draw(self, renderer):
432432
self.get_facecolor(), self.get_edgecolor(),
433433
self._linewidths, self._linestyles,
434434
self._antialiaseds, self._urls,
435-
"screen", self.get_hatchcolor()
435+
"screen", hatchcolors=self.get_hatchcolor()
436436
)
437437
except TypeError:
438438
hatchcolors_arg_supported = False
@@ -442,11 +442,12 @@ def draw(self, renderer):
442442
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
443443
args = [offsets, offset_trf, [mcolors.to_rgba("none")], self._gapcolor,
444444
self._linewidths, ilinestyles, self._antialiaseds, self._urls,
445-
"screen", self.get_hatchcolor()]
445+
"screen"]
446446

447447
if hatchcolors_arg_supported:
448448
renderer.draw_path_collection(gc, transform.frozen(), ipaths,
449-
self.get_transforms(), *args)
449+
self.get_transforms(), *args,
450+
hatchcolors=self.get_hatchcolor())
450451
else:
451452
# If the renderer does not support the hatchcolors argument,
452453
# iterate over the paths and draw them one by one.
@@ -463,11 +464,12 @@ def draw(self, renderer):
463464

464465
args = [offsets, offset_trf, self.get_facecolor(), self.get_edgecolor(),
465466
self._linewidths, self._linestyles, self._antialiaseds, self._urls,
466-
"screen", self.get_hatchcolor()]
467+
"screen"]
467468

468469
if hatchcolors_arg_supported:
469470
renderer.draw_path_collection(gc, transform.frozen(), paths,
470-
self.get_transforms(), *args)
471+
self.get_transforms(), *args,
472+
hatchcolors=self.get_hatchcolor())
471473
else:
472474
path_ids = renderer._iter_collection_raw_paths(
473475
transform.frozen(), paths, self.get_transforms())

src/_backend_agg_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
236236
"gc"_a, "master_transform"_a, "paths"_a, "transforms"_a, "offsets"_a,
237237
"offset_trans"_a, "facecolors"_a, "edgecolors"_a, "linewidths"_a,
238238
"dashes"_a, "antialiaseds"_a, "ignored"_a, "offset_position"_a,
239-
"hatchcolors"_a = py::array_t<double>().reshape({0, 4}))
239+
py::kw_only(), "hatchcolors"_a = py::array_t<double>().reshape({0, 4}))
240240
.def("draw_quad_mesh", &PyRendererAgg_draw_quad_mesh,
241241
"gc"_a, "master_transform"_a, "mesh_width"_a, "mesh_height"_a,
242242
"coordinates"_a, "offsets"_a, "offset_trans"_a, "facecolors"_a,

0 commit comments

Comments
 (0)