Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e69dbe1

Browse files
committed
Implement ArtistList.__[r]add__.
Fixes #19890.
1 parent a61f208 commit e69dbe1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,18 @@ def __getitem__(self, key):
13631363
for artist in self._axes._children
13641364
if self._type_check(artist)][key]
13651365

1366+
def __add__(self, other):
1367+
if isinstance(other, list):
1368+
return list(self) + other
1369+
elif isinstance(other, _AxesBase.ArtistList):
1370+
return list(self) + list(other)
1371+
return NotImplemented
1372+
1373+
def __radd__(self, other):
1374+
if isinstance(other, list):
1375+
return other + list(self)
1376+
return NotImplemented
1377+
13661378
def insert(self, index, item):
13671379
_api.warn_deprecated(
13681380
'3.5',

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7104,3 +7104,7 @@ def test_artist_sublists():
71047104
match='modification of the Axes.lines property'):
71057105
ax.lines[1:1] = lines[1:-2]
71067106
assert list(ax.lines) == lines
7107+
7108+
# Adding to other lists should produce a regular list.
7109+
assert ax.lines + [1, 2, 3] == [*lines, 1, 2, 3]
7110+
assert [1, 2, 3] + ax.lines == [1, 2, 3, *lines]

0 commit comments

Comments
 (0)