-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Unifying the Figure getter/setter interface to match its constructor #21549
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
Unifying the Figure getter/setter interface to match its constructor #21549
Conversation
…nts. refactored layout setting. added ability to change subplotparams post hoc. added figsize getter/setter convenience function in order to match the constructor signature of figure. added tests.
There was a problem hiding this 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.
lib/matplotlib/figure.py
Outdated
@@ -2684,6 +2888,60 @@ def get_size_inches(self): | ||
""" | ||
return np.array(self.bbox_inches.p1) | ||
|
||
def set_figsize(self, w, h=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably just use cbook._define_aliases
(see other uses in the library).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @anntzer. I made the requested change in the newest commit. Also updated the tests to match pep8.
I'm not convinced by the motivation here. When do we want to pass a figure to a plotting method while at the same time wanting the user to be able to control layout parameters? It seems the only reason to pass a figure to a method is if we want to control the layout in our method. Can you justify this a little more? Overall the new |
I think the motivation here is reasonable. We already moved to a single @stanleyjs You have taken on an ambitious project for your first PR, anything extending (let alone changing) the API tends to result in very verbose discussions (because a lot of our day-to-day pain in related to APIs that in in 20/20 hind sight were not the best). Please bear with us while we work through the process. |
Yes but my point is that currently you cannot tweak it up after the fact if you have used a colorbar so an explicit setter will fail |
Hi just wanted to bump this and see what the timeline is moving forward. A few things.
|
I will look into this from the API consistency point of view. But I'll take some time because I don't have much time for matplotlib currently. There are always tradeoffs between API improvements, compatibility with the existing API and redundant ways to do the same thing. Usually, you cannot have all. |
I have looked into this extensively, and its certainly possible, but not in a back-compatible way. Conversely you could use the current design, pull the colorbar out, hoist the parent axes to their original gridspec, and redo the layout (or vice versa), but that seems really brittle and not worth the bother. I'm not convinced there is a great use case to toggle the two layout managers that would justify adding all the extra cruft needed to make this work, particularly given how poorly |
There have been substantive changes to |
@jklymak while I still believe that it doesn't make any sense for certain constructor arguments to not have a corresponding |
We currently have
So, yes I agree that we should have |
@timhoffm yes. Sorry for the delay. I will try to get this on the list for this weekend. |
@stanleyjs are you still interested in opening a PR? |
Thank you for your work on this @stanleyjs ! I created #24617 writing up the more limited version of this PR and am going to close this. Working code is a good articulation of requirements, but I opted to open a new issue in favor of closing this PR to make it more likely for someone else to pick up this work. |
hmm |
Updated with original test from matplotlib#21549 written by @stanleyjs Co-Authored-By: Jay Stanley <stanleyjs@users.noreply.github.com>
PR Summary
Hi,
This is my first matplotlib PR. Should I base it in v3.5.x or base in main? This PR is based in main.
While building some convenience functions to automatically generate figures and/or update the parameters of passed figures, I noticed that
figure.set(figsize=(w,h))
did not work, as there was noset_figsize
function. I then noticed thatsubplotpars
,figsize
, andlayout
each lack getter/setter methods, and thus they cannot be set naively by calling.set(kwarg)
orset_kwarg
. This makes functions like the following difficult to write without having individual logic for every figure kwarg. It is better to have a standard interface of getters and setters.Edit: This PR also refactors how tight_layout and constrained_layout are set. It places all of the logic inside a set_layout function, which handles passing layout as a string (eg layout = "tight"), as a bool (eg tight_layout=True), and passing in padding parameters (eg layout = "constrained", constrained_layout={"param":"val"})
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).