Skip to content

Support Matplotlib 3.12 ArtistList location - #688

Merged
argerlt merged 2 commits into
pyxem:developfrom
cristianchiriac:fix-matplotlib-artistlist
Oct 13, 2026
Merged

argerlt merged 2 commits into
pyxem:developfrom
cristianchiriac:fix-matplotlib-artistlist

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Description of the change

Closes #686.

Matplotlib 3.12 moves Axes.ArtistList to matplotlib.artist.ArtistList (matplotlib/matplotlib#31794). On the class, Axes.ArtistList is now a deprecated property, so subscripting it in stereographic_plot.py raises TypeError: '_deprecated_property' object is not subscriptable. That happens at import time, so import orix.plot (and everything importing orix.crystal_map) fails.

This imports ArtistList from matplotlib.artist when it exists, falls back to maxes.Axes.ArtistList on older Matplotlib, and uses it in the three type annotations. black then puts COLLECTION_TYPES and the return annotation of _get_collection() on one line each. There's also a line in the Fixed section of CHANGELOG.rst.

Progress of the PR

  • Docstrings for all functions (no new functions)
  • Unit tests with pytest for all lines. The new import is exercised by every test that imports orix.plot. The fallback branch is marked pragma: no cover because only one branch runs per Matplotlib version.
  • Clean code style by running black via pre-commit (black 26.5.1, isort 9.0.2)

Minimal example of the bug fix or new feature

>>> import matplotlib
>>> matplotlib.__version__
'3.12.0.dev696+gd2115ba4e'
>>> import orix.plot  # before: TypeError: '_deprecated_property' object is not subscriptable

Tested on Python 3.12 with pytest orix/tests/test_plot: 111 passed, 13 skipped with Matplotlib 3.11.2, and the same with the 3.12.0.dev696 nightly wheel. Without the change, the nightly fails at import.

For reviewers

  • The PR title is short, concise, and will make sense 1 year later.
  • New functions are imported in corresponding __init__.py.
  • New features, API changes, and deprecations are mentioned in the unreleased
    section in CHANGELOG.rst.
  • Contributor(s) are listed correctly in __credits__ in orix/__init__.py and in
    .zenodo.json.

Matplotlib 3.12 deprecates Axes.ArtistList in favour of
matplotlib.artist.ArtistList, and the deprecated class attribute can no
longer be subscripted, so importing orix.plot failed with
"TypeError: '_deprecated_property' object is not subscriptable".
Import ArtistList from matplotlib.artist when available.

Closes #686
@argerlt
argerlt self-requested a review October 8, 2026 17:41
Comment on lines +54 to +58
try: # Matplotlib >= 3.12
from matplotlib.artist import ArtistList
except ImportError: # pragma: no cover
ArtistList = maxes.Axes.ArtistList

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For consistency, with more recent ORIX practices, please change ArtistList to mArtistList to denote it as a class inherited from matplotlib, and not an ORIX class.

try:  # Matplotlib >= 3.12
    from matplotlib.artist import ArtistList as mArtistList
except ImportError:  # pragma: no cover
    mArtistList = maxes.Axes.ArtistList

Otherwise, this is great, thank you for contributing to this project.

@argerlt
argerlt merged commit 0a04622 into pyxem:develop Oct 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: '_deprecated_property' object is not subscriptable

2 participants