diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 1544c48d43b4..9fff6161ff02 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -167,8 +167,8 @@ 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._facecolor = other._facecolor self._original_edgecolor = other._original_edgecolor + self._facecolor = other._facecolor self._original_facecolor = other._original_facecolor self._fill = other._fill self._hatch = other._hatch diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 89a77e258010..101a98212f9e 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -444,6 +444,29 @@ def test_contains_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_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_edgecolor + # when + updated.set_alpha(0.777) + # then + expected_facecolor = source_facecolor[0:3] + (0.777,) + 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):