From df749498898131c5740372d1432603e7acc27d09 Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Fri, 23 Feb 2018 21:27:01 +0100 Subject: [PATCH 1/8] fix for #10574 fix for bug described in https://github.com/matplotlib/matplotlib/issues/10574 --- lib/matplotlib/patches.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index cf8f20eb97d2..ec600509e826 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -176,7 +176,9 @@ def update_from(self, other): # For some properties we don't need or don't want to go through the # getters/setters, so we just copy them directly. self._edgecolor = other._edgecolor + self._original_edgecolor = other._original_edgecolor self._facecolor = other._facecolor + self._original_facecolor = other._original_facecolor self._fill = other._fill self._hatch = other._hatch self._hatch_color = other._hatch_color From 8f327ab6123a86616a64a673b99fb4590b469d3f Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Wed, 14 Mar 2018 12:14:47 +0100 Subject: [PATCH 2/8] patch test to set alpha after update_from to fix #10575 --- unit/test_patches.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 unit/test_patches.py diff --git a/unit/test_patches.py b/unit/test_patches.py new file mode 100644 index 000000000000..274c5896f44c --- /dev/null +++ b/unit/test_patches.py @@ -0,0 +1,22 @@ +import matplotlib.patches as mpatches + +source_facecolor = (0.234, 0.123, 0.135, 0.322) +source_egdecolor = (0.728, 0.682, 0.945, 0.268) + +def test_when_update_from_and_set_alpha_then_only_alpha_changes(): + # given + source = mpatches.Rectangle((0, 0), 1., 1., facecolor=source_facecolor, edgecolor=source_egdecolor) + updated = mpatches.Rectangle((1., 0), 1., 1., facecolor='pink', edgecolor="green") + # when + updated.update_from(source) + # then + assert updated.get_facecolor() == source_facecolor + assert updated.get_edgecolor() == source_egdecolor + # when + updated.set_alpha(0.777) + # then + expected_facecolor = source_facecolor[0:3] + (0.777,) + expected_edgecolor = source_egdecolor[0:3] + (0.777,) + assert updated.get_facecolor() == expected_facecolor + assert updated.get_edgecolor() == expected_edgecolor + From 0f1e0ea9d5951ad3fce0bdf2b09cb1f4397bf78e Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Wed, 14 Mar 2018 23:25:19 +0100 Subject: [PATCH 3/8] test to ensure #10575 is fixed test set_alpha after update_from changes only alpha in color --- lib/matplotlib/tests/test_patches.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index ff1abb9c64f4..55efc65da511 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -410,3 +410,23 @@ def test_contains_points(): expected = path.contains_points(points, transform, radius) result = ell.contains_points(points) assert np.all(result == expected) + + +def test_when_update_from_and_set_alpha_then_only_alpha_changes(): + # given + source_facecolor = (0.234, 0.123, 0.135, 0.322) + source_egdecolor = (0.728, 0.682, 0.945, 0.268) + source = mpatches.Rectangle((0, 0), 1., 1., facecolor=source_facecolor, edgecolor=source_egdecolor) + updated = mpatches.Rectangle((1., 0), 1., 1., facecolor='pink', edgecolor="green") + # when + updated.update_from(source) + # then + assert updated.get_facecolor() == source_facecolor + assert updated.get_edgecolor() == source_egdecolor + # when + updated.set_alpha(0.777) + # then + expected_facecolor = source_facecolor[0:3] + (0.777,) + expected_edgecolor = source_egdecolor[0:3] + (0.777,) + assert updated.get_facecolor() == expected_facecolor + assert updated.get_edgecolor() == expected_edgecolor From 85a8b060d23f3e22e7a11b09328b92dc37eaae83 Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Wed, 14 Mar 2018 23:29:25 +0100 Subject: [PATCH 4/8] move test to lib/matplotlib/tests/test_patches.py this test is moved to lib/matplotlib/tests/test_patches.py --- unit/test_patches.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 unit/test_patches.py diff --git a/unit/test_patches.py b/unit/test_patches.py deleted file mode 100644 index 274c5896f44c..000000000000 --- a/unit/test_patches.py +++ /dev/null @@ -1,22 +0,0 @@ -import matplotlib.patches as mpatches - -source_facecolor = (0.234, 0.123, 0.135, 0.322) -source_egdecolor = (0.728, 0.682, 0.945, 0.268) - -def test_when_update_from_and_set_alpha_then_only_alpha_changes(): - # given - source = mpatches.Rectangle((0, 0), 1., 1., facecolor=source_facecolor, edgecolor=source_egdecolor) - updated = mpatches.Rectangle((1., 0), 1., 1., facecolor='pink', edgecolor="green") - # when - updated.update_from(source) - # then - assert updated.get_facecolor() == source_facecolor - assert updated.get_edgecolor() == source_egdecolor - # when - updated.set_alpha(0.777) - # then - expected_facecolor = source_facecolor[0:3] + (0.777,) - expected_edgecolor = source_egdecolor[0:3] + (0.777,) - assert updated.get_facecolor() == expected_facecolor - assert updated.get_edgecolor() == expected_edgecolor - From e1afc168ac4355a7f692703cea6dc714d1698bbd Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Sun, 8 Apr 2018 18:02:04 +0200 Subject: [PATCH 5/8] add line breaks --- lib/matplotlib/tests/test_patches.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 55efc65da511..f5f4edd542cc 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -416,8 +416,10 @@ def test_when_update_from_and_set_alpha_then_only_alpha_changes(): # given source_facecolor = (0.234, 0.123, 0.135, 0.322) source_egdecolor = (0.728, 0.682, 0.945, 0.268) - source = mpatches.Rectangle((0, 0), 1., 1., facecolor=source_facecolor, edgecolor=source_egdecolor) - updated = mpatches.Rectangle((1., 0), 1., 1., facecolor='pink', edgecolor="green") + source = mpatches.Rectangle((0, 0), 1., 1., + facecolor=source_facecolor, edgecolor=source_egdecolor) + updated = mpatches.Rectangle((1., 0), 1., 1., + facecolor='pink', edgecolor="green") # when updated.update_from(source) # then From 6d47414b4b4830e768063b0c1792da1d8150872f Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Mon, 16 Apr 2018 20:57:54 +0200 Subject: [PATCH 6/8] typo and PEP8 fix --- lib/matplotlib/tests/test_patches.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index f5f4edd542cc..919ab7de9bca 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -411,24 +411,25 @@ def test_contains_points(): result = ell.contains_points(points) assert np.all(result == expected) - + def test_when_update_from_and_set_alpha_then_only_alpha_changes(): # given source_facecolor = (0.234, 0.123, 0.135, 0.322) - source_egdecolor = (0.728, 0.682, 0.945, 0.268) - source = mpatches.Rectangle((0, 0), 1., 1., - facecolor=source_facecolor, edgecolor=source_egdecolor) - updated = mpatches.Rectangle((1., 0), 1., 1., + source_edgecolor = (0.728, 0.682, 0.945, 0.268) + source = mpatches.Rectangle((0, 0), 1., 1., + facecolor=source_facecolor, + edgecolor=source_edgecolor) + updated = mpatches.Rectangle((1., 0), 1., 1., facecolor='pink', edgecolor="green") # when updated.update_from(source) # then assert updated.get_facecolor() == source_facecolor - assert updated.get_edgecolor() == source_egdecolor + assert updated.get_edgecolor() == source_edgecolor # when updated.set_alpha(0.777) # then expected_facecolor = source_facecolor[0:3] + (0.777,) - expected_edgecolor = source_egdecolor[0:3] + (0.777,) + expected_edgecolor = source_edgecolor[0:3] + (0.777,) assert updated.get_facecolor() == expected_facecolor assert updated.get_edgecolor() == expected_edgecolor From 1d37d4ddcb499fb707aec2415b2c0c0d61b3b28e Mon Sep 17 00:00:00 2001 From: KonradAdamczyk Date: Tue, 31 Jul 2018 21:32:03 +0200 Subject: [PATCH 7/8] fix wrong merge --- lib/matplotlib/patches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index dc51e993de03..9fff6161ff02 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -169,7 +169,7 @@ def update_from(self, other): self._edgecolor = other._edgecolor self._original_edgecolor = other._original_edgecolor self._facecolor = other._facecolor - self._original_edgecolor = other._original_edgecolor + self._original_facecolor = other._original_facecolor self._fill = other._fill self._hatch = other._hatch self._hatch_color = other._hatch_color From 08d02944f1201f89c6d0ad427cddd44f2533f0ad Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 3 Nov 2018 12:03:54 +0000 Subject: [PATCH 8/8] Whitespace fixes --- lib/matplotlib/tests/test_patches.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 6487359a5e08..101a98212f9e 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -442,7 +442,8 @@ def test_contains_points(): expected = path.contains_points(points, transform, radius) result = ell.contains_points(points) assert np.all(result == expected) - + + def test_when_update_from_and_set_alpha_then_only_alpha_changes(): # given source_facecolor = (0.234, 0.123, 0.135, 0.322) @@ -464,7 +465,8 @@ def test_when_update_from_and_set_alpha_then_only_alpha_changes(): expected_edgecolor = source_edgecolor[0:3] + (0.777,) assert updated.get_facecolor() == expected_facecolor assert updated.get_edgecolor() == expected_edgecolor - + + # Currently fails with pdf/svg, probably because some parts assume a dpi of 72. @check_figures_equal(extensions=["png"]) def test_shadow(fig_test, fig_ref): @@ -489,4 +491,3 @@ def test_shadow(fig_test, fig_ref): alpha=.5) a2.add_patch(shadow) a2.add_patch(rect) - \ No newline at end of file