matplotlib / matplotlib/matplotlib

[ENH]: generalize artists opting in-to auto limits

Open
#25,139 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Difficulty: Medium New feature
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Problem

This is triggered by #25127 most recently, but this is a discussion we have had a couple of times.

The core of the problem is that users have different expectations about what things will automatically adjust the axes limits (or not) in autolim mode. Currently `Lines`, `Patches` and `AxesImage` obligatorily participate https://github.com/matplotlib/matplotlib/blob/a046ee3febac399869c3eb6b15b8e669e37058ee/lib/matplotlib/axes/_base.py#L2459-L2483 and collections may optionally participate, but only when they are added https://github.com/matplotlib/matplotlib/blob/a046ee3febac399869c3eb6b15b8e669e37058ee/lib/matplotlib/axes/_base.py#L2260-L2273

### Proposed solution

The proposed solution is to:

- move the `_update_line_limits` and friends to the respective Artists
- add an analogous method to the base `Artist` (probably defaulting to failure)
- add a "I would like to particpate in autolimiting!" flag to base `Artist`
- in `relim` look at the flag and call the newly generalized method above on any artists that opt-in

This will involved a little bit of public API (how to set the state to opt-in) and a bunch of private API (what should the signature of the method be).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/matplotlib/axes/_base.py at the linked _update_line_limits code and the collection handling, then inspect the Artist base class and relim. Define how artists opt into autolimiting, where the existing update methods belong, and the public and private API signatures. Done means Lines, Patches, AxesImage, and optionally participating collections use the generalized behavior without breaking relim.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.