diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 74fb8f270ffe..17a9fbfd40b1 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1057,6 +1057,9 @@ def alphaState(self, alpha): return name def hatchPattern(self, hatch_style): + # The colors may come in as numpy arrays, which aren't hashable + hatch_style = (tuple(hatch_style[0]), tuple(hatch_style[1]), hatch_style[2]) + pattern = self.hatchPatterns.get(hatch_style, None) if pattern is not None: return pattern diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 49c39f883f58..dfc54e83d364 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -327,7 +327,7 @@ def _get_hatch(self, gc, rgbFace): """ Create a new hatch pattern """ - dictkey = (gc.get_hatch(), rgbFace, gc.get_rgb()) + dictkey = (gc.get_hatch(), tuple(rgbFace), tuple(gc.get_rgb())) oid = self._hatchd.get(dictkey) if oid is None: oid = self._make_id(u'h', dictkey) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf new file mode 100644 index 000000000000..a8eff09f313e Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png new file mode 100644 index 000000000000..a7f1b3b9e35d Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg new file mode 100644 index 000000000000..7dc3e3b3a284 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg @@ -0,0 +1,6861 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8cb67512afd8..79567221f161 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -660,6 +660,21 @@ def test_hist_log(): ax.set_xticks([]) ax.set_yticks([]) +@image_comparison(baseline_images=['contour_hatching']) +def test_contour_hatching(): + x = np.linspace(-3, 5, 150).reshape(1, -1) + y = np.linspace(-3, 5, 120).reshape(-1, 1) + z = np.cos(x) + np.sin(y) + + # we no longer need x and y to be 2 dimensional, so flatten them. + x, y = x.flatten(), y.flatten() + + fig = plt.figure() + ax = fig.add_subplot(111) + cs = ax.contourf(x, y, z, hatches=['-', '/', '\\', '//'], + cmap=plt.get_cmap('gray'), + extend='both', alpha=0.5) + if __name__=='__main__': import nose nose.runmodule(argv=['-s','--with-doctest'], exit=False)