Skip to content

Add new "reset" property to clear (cla) method #28974

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dberardi99
Copy link

PR summary

Added new reset property in the clear method to avoid unexpected results while working with twin axes etc.

The concept of this modification is to introduce a sort of "hard" and "soft" clear to give the user an increased control over this functionality:

  • "Hard" clear (called with clear(reset=True) or cla(reset=True)) is intended to clear data-like content as well as to clear the formatting (thus axes labels, colors, position, etc.)
  • "Soft" clear (called by default with clear() or cla()) is instead used to clear only data-like content, leaving the formatting unchanged

Closes #28268, closes #28846

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@timhoffm
Copy link
Member

timhoffm commented Oct 14, 2024

I'm a bit skeptical that adding reset kwarg may be too ad-hoc and won't carry us through all clear-related issues ( #28851). While it may be a route to make clear() behavior configurable, are we sure there are only to variants, so that a bool parameter is sufficient?

You write

When 'reset' is set to False, part of the formatting of the axis (labels and relative properties) is left unchanged.

That's too imprecise. We need to be very clear what is changed and what not.

The naming "reset" is quite generic. Have you thoroughly reflected whether this is the best name?

Is there a reason to use **kwargs? If possible, explict parameters with a default should be preferred.

@jklymak
Copy link
Member

jklymak commented Oct 14, 2024

Agree with @timhoffm that this is not the correct approach here. Multiple meanings of "clear" are just going to get confusing and there will always be the question of where to draw the line of what gets cleared and what does not.

@dberardi99
Copy link
Author

Thanks for your feedback @timhoffm and @jklymak

You're right that this is not the solution for all the problems cited in #28851 as well as that in this case an explicit parameter with a default value would be preferred being the "reset" parameter always used in the function.

Then how do we want to treat this PR? Do we want to proceed as suggested by @jklymak and as said here #28268 (comment)?
In this case this PR would close the only problems related to the labels position (that was my initial target here), leaving the other topics unsolved for now (e.g., resetting axis scale of child plot when clearing the parent one or not resetting tick label).

IMHO it is a good idea to proceed with @jklymak solution since it won't create too much confusion, but it would also be a good enhancement to make clear() behaviour more customizable (not using just a bool parameter like my "reset" but something more explanatory that could accept multiple values as you said)

That's my first PR so pardon me if it is not perfect :)

@jklymak
Copy link
Member

jklymak commented Oct 16, 2024

@dberardi99 Thanks for taking a crack at this - your contribution is appreciated. Given how mature Matplotlib is, making changes to basic functionality like ax.clear is going to need a fair bit of thought and discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs decision
3 participants