8000 Copy new attributes in Collection.update_from. · matplotlib/matplotlib@ee8dc54 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee8dc54

Browse files
committed
Copy new attributes in Collection.update_from.
These were added in #18480, and not copying them can mean that an artist that used `update_from` could get in an inconsistent state. For example, this will fix legends of colour-mapped scatter plots, where a copy of the scatter Collection is made to go in the legend. Fixes #19779.
1 parent 9e4446a commit ee8dc54

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/matplotlib/collections.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,11 @@ def update_from(self, other):
944944

945945
artist.Artist.update_from(self, other)
946946
self._antialiaseds = other._antialiaseds
947+
self._mapped_colors = other._mapped_colors
948+
self._edge_is_mapped = other._edge_is_mapped
947949
self._original_edgecolor = other._original_edgecolor
948950
self._edgecolors = other._edgecolors
951+
self._face_is_mapped = other._face_is_mapped
949952
self._original_facecolor = other._original_facecolor
950953
self._facecolors = other._facecolors
951954
self._linewidths = other._linewidths
@@ -958,7 +961,7 @@ def update_from(self, other):
958961
self._A = other._A
959962
self.norm = other.norm
960963
self.cmap = other.cmap
961-
# do we need to copy self._update_dict? -JJL
964+
self._update_dict = other._update_dict.copy()
962965
self.stale = True
963966

964967

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ def test_get_labels():
5252
@check_figures_equal()
5353
def test_label_loc_vertical(fig_test, fig_ref):
5454
ax = fig_test.subplots()
55-
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
55+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2], label='scatter')
56+
ax.legend()
5657
ax.set_ylabel('Y Label', loc='top')
5758
ax.set_xlabel('X Label', loc='right')
5859
cbar = fig_test.colorbar(sc)
5960
cbar.set_label("Z Label", loc='top')
6061

6162
ax = fig_ref.subplots()
62-
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
63+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2], label='scatter')
64+
ax.legend()
6365
ax.set_ylabel('Y Label', y=1, ha='right')
6466
ax.set_xlabel('X Label', x=1, ha='right')
6567
cbar = fig_ref.colorbar(sc)
@@ -69,14 +71,16 @@ def test_label_loc_vertical(fig_test, fig_ref):
6971
@check_figures_equal()
7072
def test_label_loc_horizontal(fig_test, fig_ref):
7173
ax = fig_test.subplots()
72-
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
74+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2], label='scatter')
75+
ax.legend()
7376
ax.set_ylabel< 8000 /span>('Y Label', loc='bottom')
7477
ax.set_xlabel('X Label', loc='left')
7578
cbar = fig_test.colorbar(sc, orientation='horizontal')
7679
cbar.set_label("Z Label", loc='left')
7780

7881
ax = fig_ref.subplots()
79-
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
82+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2], label='scatter')
83+
ax.legend()
8084
ax.set_ylabel('Y Label', y=0, ha='left')
8185
ax.set_xlabel('X Label', x=0, ha='left')
8286
cbar = fig_ref.colorbar(sc, orientation='horizontal')
@@ -88,14 +92,16 @@ def test_label_loc_rc(fig_test, fig_ref):
8892
with matplotlib.rc_context({"xaxis.labellocation": "right",
8993
"yaxis.labellocation": "top"}):
9094
ax = fig_test.subplots()
91-
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
95+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2], label='scatter')
96+
ax.legend()
9297
ax.set_ylabel('Y Label')
9398
ax.set_xlabel('X Label')
9499
cbar = fig_test.colorbar(sc, orientation='horizontal')
95100
cbar.set_label("Z Label")
96101

97102
ax = fig_ref.subplots()
98-
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
103+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2], label='scatter')
104+
ax.legend()
99105
ax.set_ylabel('Y Label', y=1, ha='right')
100106
ax.set_xlabel('X Label', x=1, ha='right')
101107
cbar = fig_ref.colorbar(sc, orientation='horizontal')

0 commit comments

Comments
 (0)
0