8000 FIX patch.update_from to also copy _original_edge/facecolor by KonradAdamczyk · Pull Request #10575 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX patch.update_from to also copy _original_edge/facecolor #10575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
0