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

Skip to content

Commit 7b547ea

Browse files
rcomerQuLogic
authored andcommitted
Backport PR #28993: FIX: contourf hatches use multiple edgecolors
1 parent cbebc61 commit 7b547ea

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/matplotlib/contour.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,12 +1415,16 @@ def draw(self, renderer):
14151415
super().draw(renderer)
14161416
return
14171417
# In presence of hatching, draw contours one at a time.
1418+
edgecolors = self.get_edgecolors()
1419+
if edgecolors.size == 0:
1420+
edgecolors = ("none",)
14181421
for idx in range(n_paths):
14191422
with cbook._setattr_cm(self, _paths=[paths[idx]]), self._cm_set(
14201423
hatch=self.hatches[idx % len(self.hatches)],
14211424
array=[self.get_array()[idx]],
14221425
linewidths=[self.get_linewidths()[idx % len(self.get_linewidths())]],
14231426
linestyles=[self.get_linestyles()[idx % len(self.get_linestyles())]],
1427+
edgecolors=edgecolors[idx % len(edgecolors)],
14241428
):
14251429
super().draw(renderer)
14261430

lib/matplotlib/tests/test_contour.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ def test_given_colors_levels_and_extends(split_collections):
198198
_maybe_split_collections(split_collections)
199199

200200

201+
@image_comparison(['contourf_hatch_colors'],
202+
remove_text=True, style='mpl20', extensions=['png'])
203+
def test_hatch_colors():
204+
fig, ax = plt.subplots()
205+
cf = ax.contourf([[0, 1], [1, 2]], hatches=['-', '/', '\\', '//'], cmap='gray')
206+
cf.set_edgecolors(["blue", "grey", "yellow", "red"])
207+
208+
201209
@pytest.mark.parametrize("split_collections", [False, True])
202210
@image_comparison(['contour_log_locator.svg'], style='mpl20', remove_text=False)
203211
def test_log_locator_levels(split_collections):

0 commit comments

Comments
 (0)