From 8e1ac4c20a9ac9919e145d7b892a9b2808572595 Mon Sep 17 00:00:00 2001 From: pharshalp Date: Sun, 23 Sep 2018 02:26:42 -0400 Subject: [PATCH] Fix for github issue 1302 based on the github discussion + test --- lib/matplotlib/axes/_axes.py | 14 ++++++++++++++ lib/matplotlib/tests/test_image.py | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index ea1c53aa39c4..1854312c4981 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5789,6 +5789,13 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None, corners = (minx, miny), (maxx, maxy) self.update_datalim(corners) self.autoscale_view() + # The following block of code addresses github issue #1302 + for face_color in ['facecolor', 'facecolors']: + try: + if kwargs.get(face_color).lower() == 'none': + collection._is_stroked = False + except AttributeError: + pass return collection @_preprocess_data(label_namer=None) @@ -6002,6 +6009,13 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None, corners = (minx, miny), (maxx, maxy) self.update_datalim(corners) self.autoscale_view() + # The following block of code addresses github issue #1302 + for face_color in ['facecolor', 'facecolors']: + try: + if kwargs.get(face_color).lower() == 'none': + collection._is_stroked = False + except AttributeError: + pass return collection @_preprocess_data(label_namer=None) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 40abbe9dfb66..04a842ee548e 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -922,3 +922,19 @@ def test_relim(): ax.relim() ax.autoscale() assert ax.get_xlim() == ax.get_ylim() == (0, 1) + + +def test_edgefacecolor_pcolor_pcolormesh(): + # Test that pcolor/pcolormesh honours edgecolors kwarg when facecolors + # is set to 'none' (github issue #1302 and fixed by PR #12226). + fig, ax = plt.subplots(2) + im0 = ax[0].pcolor(np.arange(12).reshape(4, 3), + edgecolors='red', facecolors='none') + im1 = ax[1].pcolormesh(np.arange(12).reshape(4, 3), + edgecolors='red', facecolors='none') + # triggering draw() to make sure that the edges of the mesh are drawn. + fig.canvas.draw() + np.testing.assert_equal(im0.get_edgecolors(), + np.array([[1., 0., 0., 1.]])) + np.testing.assert_equal(im1.get_edgecolors(), + np.array([[1., 0., 0., 1.]]))