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

Skip to content

Implement ArtistList.__[r]add__. #19902

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

Merged
merged 1 commit into from
Apr 8, 2021
Merged
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
10 changes: 10 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,16 @@ def __getitem__(self, key):
for artist in self._axes._children
if self._type_check(artist)][key]

def __add__(self, other):
if isinstance(other, (list, _AxesBase.ArtistList)):
return [*self, *other]
return NotImplemented

def __radd__(self, other):
if isinstance(other, list):
return other + list(self)
return NotImplemented

def insert(self, index, item):
_api.warn_deprecated(
'3.5',
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7104,3 +7104,7 @@ def test_artist_sublists():
match='modification of the Axes.lines property'):
ax.lines[1:1] = lines[1:-2]
assert list(ax.lines) == lines

# Adding to other lists should produce a regular list.
assert ax.lines + [1, 2, 3] == [*lines, 1, 2, 3]
assert [1, 2, 3] + ax.lines == [1, 2, 3, *lines]