Skip to content

Commit ab101e9

Browse files
committed
Merge pull request #4474 from jpallister/master
BUG: fix for hatching problems inside PDF legends
2 parents 62bef78 + a182a76 commit ab101e9

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/matplotlib/backends/backend_pdf.py

+7
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,7 @@ def delta(self, other):
22832283
needed to transform self into other.
22842284
"""
22852285
cmds = []
2286+
fill_performed = False
22862287
for params, cmd in self.commands:
22872288
different = False
22882289
for p in params:
@@ -2301,7 +2302,13 @@ def delta(self, other):
23012302
if different:
23022303
break
23032304

2305+
# Need to update hatching if we also updated fillcolor
2306+
if params == ('_hatch',) and fill_performed:
2307+
different = True
2308+
23042309
if different:
2310+
if params == ('_fillcolor',):
2311+
fill_performed = True
23052312
theirs = [getattr(other, p) for p in params]
23062313
cmds.extend(cmd(self, *theirs))
23072314
for p in params:
Binary file not shown.

lib/matplotlib/tests/test_backend_pdf.py

+12
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,15 @@ def test_composite_image():
107107
with PdfPages(io.BytesIO()) as pdf:
108108
fig.savefig(pdf, format="pdf")
109109
assert len(pdf._file.images.keys()) == 2
110+
111+
112+
@image_comparison(baseline_images=['hatching_legend'],
113+
extensions=['pdf'])
114+
def test_hatching_legend():
115+
"""Test for correct hatching on patches in legend"""
116+
fig = plt.figure(figsize=(1, 2))
117+
118+
a = plt.Rectangle([0, 0], 0, 0, facecolor="green", hatch="XXXX")
119+
b = plt.Rectangle([0, 0], 0, 0, facecolor="blue", hatch="XXXX")
120+
121+
fig.legend([a, b, a, b], ["", "", "", ""])

0 commit comments

Comments
 (0)