8000 [MNT]: Define Axes.clear semantics · Issue #28851 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[MNT]: Define Axes.clear semantics #28851

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

Open
timhoffm opened this issue Sep 20, 2024 · 1 comment
Open

[MNT]: Define Axes.clear semantics #28851

timhoffm opened this issue Sep 20, 2024 · 1 comment

Comments

@timhoffm
Copy link
Member
timhoffm commented Sep 20, 2024

Summary

Axes.clear() / Axes.cla() are only documented as "Clear the Axes". What exactly "clear" means is neither documented nor well defined. We reset some stuff and keep other.

This leads to a number of issues:

There has been some inital work in #23839, but the topic is not completely solved.

Proposed fix

We need to define what clear means.

First on an abstract level: This could be a starting point:

  • All data-like content should be removed (actual data, labels, etc.)
  • Layout should stay (axes position, twinning)
  • Formatting: t.b.d.

When the high-level definition is agreed upon, we need to define what that means for concrete cases.
e.g. it's clear that we remove label content. Should label positions also be reset (e.g. if somebody has moved the xlabel to top)? - This may also depend on the anticipated use case: One wants to reuse the Axes for a new plot. How similar is it to the old plot. Does it only get new data and labels or could it be a completely different plot?

@anntzer
Copy link
Contributor
anntzer commented Sep 24, 2024

Also related to #12819 / #23503 ("Should clearing a shared axes reset its scale?")


In fact, thinking about this again, I suspect that "having a consistent behavior when only one of a shared axes is cleared" would more or less impose some choices:

  • clearing should not reset the scale (because the shared axes should keep its scale).
  • clearing should not reset the limits (because the shared axes should keep its limits).

However! this causes other problems, namely that after clearing, the cached data limits become completely wrong. I would guess the "proper" fix there would be the "lazy datalims" idea floated at #28101 (comment).

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

Successfully merging a pull request may close this issue.

2 participants
0