-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Offsetbox default arguments #24652
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
Offsetbox default arguments #24652
Conversation
…correct location. Added unit test for change.
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.
Thanks for the PR! For ease of review, suggest a description of the change and moving the issues from title to the description. |
lib/matplotlib/offsetbox.py
Outdated
@@ -369,12 +369,12 @@ def draw(self, renderer): | |||
|
|||
|
|||
class PackerBase(OffsetBox): | |||
def __init__(self, pad=None, sep=None, width=None, height=None, | |||
def __init__(self, pad=0., sep=None, width=None, height=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.
I think the same problem holds for sep as well?
Edited: width and height are calculated, but sep must be set.
lib/matplotlib/offsetbox.py
Outdated
align="baseline", mode="fixed", children=None): | ||
""" | ||
Parameters | ||
---------- | ||
pad : float, optional | ||
pad : float, required |
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.
It is still optional, just that it has a correct default now.
Can you please how the outcome of the example code in #24620? Ideally as an image test, but if nothing else just paste the result here. |
try: | ||
pb = PaddedBox(at, patch_attrs={'facecolor': 'r'}, draw_frame=True) | ||
except: | ||
raise Exception("incorrect default value") |
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.
There is no need to do this in a test. The test will fail if there is an exception anyway, so skip the try-except.
You can add a comment like
# smoke test for correct default value though
This was our result when running the code from 24620 with the default padding of 0. Additionally, we can see the result for padding=5 below: |
I'm moving this to draft. Feel free to move back when ready for review. |
There is an update in #24620 which shows that PaddedBox is indeed working. And it looks like the proposed solution is not fully handling it. Hence, my suggestion is to drop the location changes and just go with the default argument ones. |
We have made the changes according to your request to use the default values. Would you know how to resolve the CircleCi errors? |
The Circle CI issue is a bit weird. It it not related to the contents of your PR anyway. I think I've seen some issue recently where a particular user couldn't run the tests and the best guess was that the GitHub user name was changed. Would that possibly be the case here? Has anyone of you changed GitHub user name after you created your account? |
change of name doesn't seem to be the case here. any other possible reasons for the error? |
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.
Just some minor comments. The testing is good to get correct though.
One may consider changing optional
to default: 0.0
in the doc strings. (Or add Default: 0.0.
to the description, but I think the first is preferred.)
# smoke test for correct default value though | ||
fig, ax = plt.subplots() | ||
at = AnchoredText("foo", 'upper left') | ||
pb = PaddedBox(at, patch_attrs={'facecolor': 'r'}, draw_frame=True) |
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 test passes on main as well. (As the fact that pad is None is not a problem until later on.)
You need to do:
ax.add_artist(pb)
fig.draw_without_rendering()
If you can also add a similar thing for one of the packers that would be great! Can go in the same test/figure. There is a previous test for the packers that you can just copy the relevant code from, but leave the pad and sep arguments out.
Co-authored-by: Oscar Gustafsson <[email protected]>
Co-authored-by: Oscar Gustafsson <[email protected]>
Co-authored-by: Oscar Gustafsson <[email protected]>
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!
I guess this is good to go now. The addition of HPacker/VPacker tests is maybe not so clear, but it will work and test what is expected.
An better option is to simply remove the two previous lines where pad and sep are set as they are now redundant.
Whoever merges this: please squash the commits. (I take it that you are using the web-based interface for editing the files?)
I took the liberty to commit this change. |
Thanks @Ali-Msk and congratulations on your first contribution to Matplotlib! We hope to see you again. |
Closes matplotlib#24652 Co-authored-by: Skhaki18 <[email protected]> Co-authored-by: Krutarth Patel <[email protected]> Co-authored-by: Oscar Gustafsson <[email protected]> Co-authored-by: Tim Hoffmann <[email protected]>
PR Summary
Closes #24623
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst