8000 pass hatchcolor arg only if it is supported by the renderer. and made… · matplotlib/matplotlib@7e46707 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e46707

Browse files
committed
pass hatchcolor arg only if it is supported by the renderer. and made suggested changes.
1 parent 9d0ec23 commit 7e46707

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,10 @@ def delta(self, other):
26062606
different = ours is not theirs
26072607
else:
26082608
different = bool(ours != theirs)
2609-
except ValueError:
2609+
except (ValueError, DeprecationWarning):
2610+
# numpy version < 1.25 raises DeprecationWarning when array shapes
2611+
# mismatch, unlike numpy >= 1.25 which raises ValueError.
2612+
# This should be removed when numpy < 1.25 is no longer supported.
26102613
ours = np.asarray(ours)
26112614
theirs = np.asarray(theirs)
26122615
different = (ours.shape != theirs.shape or

lib/matplotlib/collections.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -420,25 +420,40 @@ def draw(self, renderer):
420420
gc, paths[0], combined_transform.frozen(),
421421
mpath.Path(offsets), offset_trf, tuple(facecolors[0]))
422422
else:
423-
if self._gapcolor is not None:
424-
# First draw paths within the gaps.
425-
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
423+
# Find whether renderer.draw_path_collection() takes hatchcolor parameter
424+
hatchcolors_arg_supported = True
425+
try:
426426
renderer.draw_path_collection(
427-
gc, transform.frozen(), ipaths,
427+
gc, transform.frozen(), [],
428428
self.get_transforms(), offsets, offset_trf,
429-
[mcolors.to_rgba("none")], self._gapcolor,
430-
self._linewidths, ilinestyles,
429+
self.get_facecolor(), self.get_edgecolor(),
430+
self._linewidths, self._linestyles,
431431
self._antialiaseds, self._urls,
432-
"screen", self.get_hatchcolor())
433-
434-
renderer.draw_path_collection(
435-
gc, transform.frozen(), paths,
436-
self.get_transforms(), offsets, offset_trf,
437-
self.get_facecolor(), self.get_edgecolor(),
438-
self._linewidths, self._linestyles,
439-
self._antialiaseds, self._urls,
440-
"screen", # offset_position, kept for backcompat.
441-
self.get_hatchcolor())
432+
"screen", self.get_hatchcolor()
433+
)
434+
except TypeError:
435+
hatchcolors_arg_supported = False
436+
437+
if self._gapcolor is not None:
438+
# First draw paths within the gaps.
439+
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
440+
args = [gc, transform.frozen(), ipaths, self.get_transforms(),
441+
offsets, offset_trf, [mcolors.to_rgba("none")],
442+
self._gapcolor, self._linewidths, ilinestyles,
443+
self._antialiaseds, self._urls, "screen"]
444+
if hatchcolors_arg_supported:
445+
args.append(self.get_hatchcolor())
446+
447+
renderer.draw_path_collection(*args)
448+
449+
args = [gc, transform.frozen(), paths, self.get_transforms(),
450+
offsets, offset_trf, self.get_facecolor(),
451+
self.get_edgecolor(), self._linewidths, self._linestyles,
452+
self._antialiaseds, self._urls, "screen"]
453+
if hatchcolors_arg_supported:
454+
args.append(self.get_hatchcolor())
455+
456+
renderer.draw_path_collection(*args)
442457

443458
gc.restore()
444459
renderer.close_group(self.__class__.__name__)

0 commit comments

Comments
 (0)
0