Skip to content

Commit c7a01db

Browse files
authored
Merge pull request #19902 from QuLogic/artistlist-add
Implement ArtistList.__[r]add__.
2 parents e14cc7b + cd057a9 commit c7a01db

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,16 @@ 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, _AxesBase.ArtistList)):
1368+
return [*self, *other]
1369+
return NotImplemented
1370+
1371+
def __radd__(self, other):
1372+
if isinstance(other, list):
1373+
return other + list(self)
1374+
return NotImplemented
1375+
13661376
def insert(self, index, item):
13671377
_api.warn_deprecated(
13681378
'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)