Skip to content

Commit 20a6e60

Browse files
committed
Fix a crash when saving to PDF or SVG with contour hatching.
1 parent c24c02d commit 20a6e60

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

lib/matplotlib/backends/backend_pdf.py

+3
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@ def alphaState(self, alpha):
10571057
return name
10581058

10591059
def hatchPattern(self, hatch_style):
1060+
# The colors may come in as numpy arrays, which aren't hashable
1061+
hatch_style = (tuple(hatch_style[0]), tuple(hatch_style[1]), hatch_style[2])
1062+
10601063
pattern = self.hatchPatterns.get(hatch_style, None)
10611064
if pattern is not None:
10621065
return pattern

lib/matplotlib/backends/backend_svg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def _get_hatch(self, gc, rgbFace):
327327
"""
328328
Create a new hatch pattern
329329
"""
330-
dictkey = (gc.get_hatch(), rgbFace, gc.get_rgb())
330+
dictkey = (gc.get_hatch(), tuple(rgbFace), tuple(gc.get_rgb()))
331331
oid = self._hatchd.get(dictkey)
332332
if oid is None:
333333
oid = self._make_id(u'h', dictkey)
Binary file not shown.

lib/matplotlib/tests/test_axes.py

+15
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,21 @@ def test_hist_log():
660660
ax.set_xticks([])
661661
ax.set_yticks([])
662662

663+
@image_comparison(baseline_images=['contour_hatching'])
664+
def test_contour_hatching():
665+
x = np.linspace(-3, 5, 150).reshape(1, -1)
666+
y = np.linspace(-3, 5, 120).reshape(-1, 1)
667+
z = np.cos(x) + np.sin(y)
668+
669+
# we no longer need x and y to be 2 dimensional, so flatten them.
670+
x, y = x.flatten(), y.flatten()
671+
672+
fig = plt.figure()
673+
ax = fig.add_subplot(111)
674+
cs = ax.contourf(x, y, z, hatches=['-', '/', '\\', '//'],
675+
cmap=plt.get_cmap('gray'),
676+
extend='both', alpha=0.5)
677+
663678
if __name__=='__main__':
664679
import nose
665680
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)