8000 Addressing issue #7434: Adding kwarg to Figure.clf() to refetch rcParams and update existing object by nasgold · Pull Request #21097 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Addressing issue #7434: Adding kwarg to Figure.clf() to refetch rcParams and update existing object #21097

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

Closed
wants to merge 137 commits into from

Conversation

nasgold
Copy link
@nasgold nasgold commented Sep 16, 2021

PR Summary

Adding refetch_rcparams kwarg to Figure.clf() that defaults to False to maintain existing, desired behavior. If set to True, however, the Figure.clf() call will re-consult rcParams and update the already extant object. Some (myself included) might find the default behavior counterintuitive, and adding in this kwarg makes behavior either way more explicit.

If the PR is accepted I will document the API change and make an entry in the "next_whats_new" file.

closes #7434 [@tacaswell edited to add GH xrefs]

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

story645 and others added 30 commits August 26, 2021 23:06
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Fixes matplotlib#20516

PGF's `random steps` decoration seems to be the most similar,
but does not exactly match the behaviour described in matplotlib's docs.
Therefore I repurposed the `randomness` argument as a seed to give
control on how the line looks afterwards.
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Switch documented deprecations in mathtext by `__getattr__` deprecations
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
…_output

API: rename draw_no_output to draw_without_rendering
Make warning for no-handles legend more explicit.
Remove unused HostAxes._get_legend_handles.
- parse() already normalizes prop=None to prop=FontProperties().
- We don't need to explicitly attach a canvas to a plain Figure() before
  calling savefig() anymore; FigureCanvasBase is always attached and
  handles the dispatching to the correct concrete canvas class.
According to the docs, this function was added in GTK 2.2, so probably
was only needed when we supported GTK2.

It also no longer exists in GTK4.
Since these examples don't need to support the very oldest GTK3, I took
the opportunity to rewrite them using the recommended Application-styled
model.
The `Gtk.Window.destroy` doesn't work, but `.close` correctly triggers
our cleanup.
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 while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. 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.

@@ -119,7 +120,63 @@ def test_clf_keyword():

fig2, ax2 = plt.subplots(2, 1, num=1, clear=True)
assert fig0 is fig2
assert [t.get_text() for t in fig2.texts] == []
Copy link
Member

Choose a reason for hiding this comment

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

I think you dropped this line by accident?

@@ -3,7 +3,7 @@
from pathlib import Path
import platform
from threading import Timer
from types import SimpleNamespace
from types import BuiltinFunctionType, SimpleNamespace
Copy link
Member

Choose a reason for hiding this comment

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

I don't see where you are using this:

Suggested change
from types import BuiltinFunctionType, SimpleNamespace
from types import SimpleNamespace

raise ValueError(
f"figure size must be positive finite not {figsize}"
)
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
Copy link
Member

Choose a reason for hiding this comment

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

OK, this is all copied from __init__ which is great, except its usually better not to copy (suppose we want to add a new rcParam, now we need to add it in two places). Can this be cleanly refactored into a helper that is called by both __init__ and clf? Thanks!

@tacaswell tacaswell added this to the v3.6.0 milestone Sep 22, 2021
@tacaswell
Copy link
Member

Well, this is what I suggested in #7434! If we are going to do this, I still think this is the way to do it, but do we think this is a good idea?

@nasgold In your comment you seem rather down on this feature! Given that this has been sitting from ~2016 with no additional agitation, maybe this is something that we do not actually need?

This PR raises a question of if ax.cla should also get a similar flag? It also jumps into a discussion we have been slowly starting to have of what does clearing a figure/axes even mean? From looking through the code it looks like the people implementing the code have not had a unified opinion on that (based on how throughly different parts of the code "clear" things).


I agree with all of @jklymak 's line comments I also suspect you will need to run https://github.com/matplotlib/matplotlib/blob/master/tools/boilerplate.py to update the signature and docstring of the auto-generated pyplot functions.


No matter where this lands, thank you for you work on this @nasgold ! Even if we ultimately close this PR (and the other draft PR to address #7434) and #7434 as "wont-fix", re-surfacing this for discussion is valuable.

@jklymak jklymak marked this pull request as draft October 12, 2021 12:29
@jklymak
Copy link
Member
jklymak commented Oct 12, 2021

poppin to draft until the review comments are looked at. Feel free to pop back on the queue!

@tacaswell
Copy link
Member

This PR is affected by a re-writing of our history to remove a large number of accidentally committed files see discourse for details.

To recover this PR it will need be rebased onto the new default branch (main). There are several ways to accomplish this, but we recommend (assuming that you call the matplotlib/matplotlib remote "upstream"

git remote update
git checkout main
git merge --ff-only upstream/main
git checkout YOUR_BRANCH
git rebase --onto=main upstream/old_master
# git rebase -i main # if you prefer
git push --force-with-lease   # assuming you are tracking your branch

If you do not feel comfortable doing this or need any help please reach out to any of the Matplotlib developers. We can either help you with the process or do it for you.

Thank you for your contributions to Matplotlib and sorry for the inconvenience.

@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 5, 2022
@tacaswell tacaswell removed this from the v3.7.0 milestone Dec 16, 2022
@tacaswell
Copy link
Member

I am going to close this PR because it has been quiet for more than a year, still needs the rebase from our history-rewrite issue, and because we still have not decided what "should" happen in these cases.

Thank you for your work on this @nasgold even if we did not ultimately merge it. I hope we will hear from you again.

@tacaswell tacaswell closed this Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

consult rcParams for Figures on fig.clf
0