Skip to content

Introduce ArtistList for FigureBase#31746

Draft
rcomer wants to merge 2 commits into
matplotlib:mainfrom
rcomer:fig-artistlist
Draft

Introduce ArtistList for FigureBase#31746
rcomer wants to merge 2 commits into
matplotlib:mainfrom
rcomer:fig-artistlist

Conversation

@rcomer

@rcomer rcomer commented May 25, 2026

Copy link
Copy Markdown
Member

PR summary

At #31730 (comment) Tom said

We deprecated directly mutating the artist lists on Axes a while ago, but apparently forgot to do that on Figure as well!

This PR generalises the ArtistList so it can work for both figures and axes. The new _FigureArtistList subclasses it just to add the deprecated methods. I adapted the deprecated methods and their tests from #18216, where this was originally done for Axes. Note that fig.subfigures is still a plain list. I do not think subfigures belong in fig._children, but rather should have their own handling similar to fig.axes. That can be done separately.

AI Disclosure

I asked duck.ai how to get a class as a string, to use in the ArtistList repr self._parent.__class__.__name__.

PR checklist

@rcomer rcomer added API: changes Changes to the public API, typically requiring deprecation. status: waiting for other PR labels May 25, 2026
@github-actions github-actions Bot added topic: mplot3d GUI: Qt backend: cairo topic: axes topic: figures and subfigures CI: Run cibuildwheel Run wheel building tests on a PR CI: Run cygwin Run cygwin tests on a PR Documentation: examples files in galleries/examples Documentation: tutorials files in galleries/tutorials Documentation: devdocs files in doc/devel Documentation: user guide files in galleries/users_explain or doc/users labels May 25, 2026
@rcomer rcomer added this to the v3.12.0 milestone May 25, 2026
@rcomer

rcomer commented May 25, 2026

Copy link
Copy Markdown
Member Author

It seems I have discovered something that only works at py314 🧐

@rcomer

This comment was marked as outdated.

@rcomer rcomer force-pushed the fig-artistlist branch 3 times, most recently from 527f6fe to 81d29da Compare May 26, 2026 20:21
Following matplotlib#18216 for Axes artists, combine all figure artists except
axes and subfigures into a single list and deprecate modifying the lists
directly.
Comment on lines +483 to +485
if sys.version_info[:2] < (3, 14):
# Including the collections.abc string in skip_file_prefixes is not yet honored.
# Add the relevant frame count to the stacklevel instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find anything in the python changenotes to understand what changed here, but I have verified that the relevant test passes with python 3.14.0.

@rcomer

This comment was marked as outdated.

@rcomer rcomer marked this pull request as ready for review May 27, 2026 20:21
@timhoffm

This comment was marked as outdated.

@timhoffm

This comment was marked as outdated.

@rcomer

This comment was marked as outdated.

@rcomer rcomer marked this pull request as draft May 28, 2026 10:47
@timhoffm

This comment was marked as outdated.

@rcomer

This comment was marked as outdated.

@rcomer

This comment was marked as outdated.

The inheritance diagram in the artists API docs broke without these.
@rcomer

This comment was marked as outdated.

@rcomer rcomer marked this pull request as ready for review May 30, 2026 15:49
Comment thread lib/matplotlib/figure.py
Comment on lines +121 to +122
A sublist of Figure children based on their type. This subclass exists only to
provide deprecation warnings. When the deprecations expire, use ArtistList

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to add

if isinstance(parent, FigureBase):
    _api.warn_deprecated(...)

or even

self.warn_deprecated_if_on_figure(...)

to the regular ArtistList methods?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArtistList is already immutable. It doesn’t have these methods.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. There's a lot of unforeseen complexity in the migration of ArtistList from AxesBase to artist, which gives me a bit of a headeache overlooking the complete PR. In hindsight it would likely have been better to either split this in two PRs / commits: (1) move ArtistList (2) use ArtistList in Figure; or alternatively just duplicate the 70 lines of ArtistList in Figure, and when the Figure deprecations run out and both classes become identical merge them back together. But I'm somewhat reluctant to request that now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry. It did occur to me when I was moving it that splitting into separate commits for moving and modifying might help the review, but at the time I couldn't quite see how to split it. I will have a go at just moving it in a separate branch and if it works I'll make a prequel PR.

@rcomer rcomer marked this pull request as draft May 31, 2026 09:51
@rcomer

rcomer commented May 31, 2026

Copy link
Copy Markdown
Member Author

Hid the discussion about doc-failure debugging as that is now fixed in #31794 and summarised at #31794 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API: changes Changes to the public API, typically requiring deprecation. Documentation: examples files in galleries/examples Documentation: tutorials files in galleries/tutorials Documentation: user guide files in galleries/users_explain or doc/users status: waiting for other PR topic: axes topic: figures and subfigures topic: text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants