Skip to content
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

Add get/set methods for DPI in SubFigure #23276

Merged
merged 5 commits into from
Jun 17, 2022

Conversation

scottjones03
Copy link
Contributor

@scottjones03 scottjones03 commented Jun 15, 2022

PR Summary

This fixes the following error:

matplotlib\lib\text.py line 1489, dop = self.figure.get_dpi()/72. AttributeError: 'SubFigure' object has no attribute 'get_dpi'.

Effect: in v3.5.2 it is not possible to save a figure with a subfigure to a PDF.

PR Checklist

Tests and Styling

  • [N/A ] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A ] New features are documented, with examples if plot related.
  • [N/A ] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

This fixes the following error: 

matplotlib\lib\text.py line 1489, dop = self.figure.get_dpi()/72. AttributeError: 'SubFigure' object has no attribute 'get_dpi'.

Effect: in v3.5.2 it is not possible to save a figure with a subfigure to a PDF.
@anntzer
Copy link
Contributor

anntzer commented Jun 15, 2022

Should we really allow setting a subfigure's dpi (which actually affects the entire figure)? This is not so clear to me...

@jklymak
Copy link
Member

jklymak commented Jun 15, 2022

Everywhere else we just use the getter: self.figure.dpi which FAICT works. So maybe just change the get_dpi? We should probably deprecate set/get_dpi so we don't have different implementations....

@anntzer artist.figure.dpi = ... just passes up to the parent.

I don't think users should ever be setting the dpi except on creation or output. but....

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.

@scottjones03
Copy link
Contributor Author

Everywhere else we just use the getter: self.figure.dpi which FAICT works. So maybe just change the get_dpi? We should probably deprecate set/get_dpi so we don't have different implementations....

@anntzer artist.figure.dpi = ... just passes up to the parent.

I don't think users should ever be setting the dpi except on creation or output. but....

I think it makes sense to deprecate the get/set methods at some point, but for now we should at least make it consistent with the Figures object as there could be more bugs related to this elsewhere.

@scottjones03
Copy link
Contributor Author

Should we really allow setting a subfigure's dpi (which actually affects the entire figure)? This is not so clear to me...

This changes the parent Figure's dpi, so it wouldn't be a problem. Also, this is the current behaviour anyway as we allow subfig.dpi = ....

@anntzer
Copy link
Contributor

anntzer commented Jun 15, 2022

@jklymak I'll happily defer to your judgment here, was just raising the point in case it was missed.

@jklymak
Copy link
Member

jklymak commented Jun 15, 2022

Sure, we can add this (after you fix the flake8 lining errors)

However, please also consider changing the internal use of get/set. I think there are only about a dozen of them; that gives us a deprecation path. Thanks!

@scottjones03
Copy link
Contributor Author

Sure, we can add this (after you fix the flake8 lining errors)

However, please also consider changing the internal use of get/set. I think there are only about a dozen of them; that gives us a deprecation path. Thanks!

Sure will take a look at it

@scottjones03
Copy link
Contributor Author

Sure, we can add this (after you fix the flake8 lining errors)

However, please also consider changing the internal use of get/set. I think there are only about a dozen of them; that gives us a deprecation path. Thanks!

#23278

@oscargus
Copy link
Contributor

I guess it would be good to add a smoke test (basically run the commands that now gives an error without actually checking the output). But maybe not worth it if this is just a temporary fix?

This should go in 3.5.3, right?

@oscargus oscargus added this to the v3.5.3 milestone Jun 15, 2022
@jklymak jklymak added PR: bugfix Pull requests that fix identified bugs status: needs tests labels Jun 15, 2022
@tacaswell tacaswell modified the milestones: v3.5.3, v3.6.0 Jun 15, 2022
@tacaswell
Copy link
Member

I would put this is 3.6 (new feature) and #23278 for 3.5.3 (bug fix by changing internal usage). It is a bit hair-splitting and I will defer to anyone who has a strong view on this.

@tacaswell
Copy link
Member

The docs build failed on a git checkout problem, restarted.

@jklymak
Copy link
Member

jklymak commented Jun 15, 2022

Subfigures are broken without this if certain artists are added to the subfigure, so I think it needs to be a bugfix

@scottjones03
Copy link
Contributor Author

scottjones03 commented Jun 15, 2022

Subfigures are broken without this if certain artists are added to the subfigure, so I think it needs to be a bugfix

As mentioned, there is now a new PR that fixes this bug. This PR would now be a feature.

@scottjones03
Copy link
Contributor Author

I guess it would be good to add a smoke test (basically run the commands that now gives an error without actually checking the output). But maybe not worth it if this is just a temporary fix?

This should go in 3.5.3, right?

#23278 would you rather this other PR be smoke tested? This one would not need a smoke test as it is no longer a bug fix.

@tacaswell
Copy link
Member

This one would not need a smoke test as it is no longer a bug fix.

This probably should get an explicit test that the methods work as expected. Probably something like make a figure with subfigures, make sure that the get_dpi on the parent and children are consistent and that calling set_dpi on the child affects both the parent and its siblings.

@jklymak
Copy link
Member

jklymak commented Jun 15, 2022

OK, but I think set_dpi and get_dpi should just be deprecated across the board, so not much need for a test?

@scottjones03
Copy link
Contributor Author

OK, but I think set_dpi and get_dpi should just be deprecated across the board, so not much need for a test?

I kinda see your point. Given that set_dpi and get_dpi is deprecated internally from the other PR, we can decline this PR and have a case where we don't advertise to users that they can change the parent dpi from the child. The downside here is the inconsistency between the figure get/set methods and the subfigure lack of get/set methods could be buggy for users who accept both figure/subfigure types for a figure in their code (like it has been done internally).

@@ -2046,6 +2046,23 @@ def dpi(self):
def dpi(self, value):
self._parent.dpi = value
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a self.stale = True here? (For symmetry with set_dpi?)

(Maybe not a question for you @scottjones03 though.)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, but in practice the parent will catch this and trigger the required re-draw.

@tacaswell
Copy link
Member

set_dpi and get_dpi should just be deprecated across the board, so not much need for a test?

fair, but we are not deprecating them on Figure yet, we should try to make SubFigure behave as much like as possible, and when we lift the dpi tracking up a level, this will be far from the gnarliest thing we will have to deal with!.

@tacaswell tacaswell merged commit d417b98 into matplotlib:main Jun 17, 2022
@tacaswell
Copy link
Member

Hi-five ✋ on merging your first pull request to Matplotlib, @scottjones03 ! We hope you stick around and invite you to continue to take an active part in Matplotlib!

Your choices aren’t limited to programming 😉 – you can review pull requests, help us stay on top of new and old issues, develop educational material, refresh our documentation, work on our website, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://matplotlib.org/stable/devel/index

Also, consider joining our mailing list ✉️. This is a great way to connect with other people in our community and be part of important conversations that affect the development of Matplotlib.

If you haven’t yet, do join us on gitter and discourse 🗣. The former is a chat platform, which is great when you have any questions on process or how to fix something, the latter is a forum which is useful for longer questions and discussions.

Last but not least, we have a monthly meeting 👥 for new contributors and a weekly meeting for the maintainers, everyone is welcome to join both! You can find out more about our regular project meetings in this calendar page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bugfix Pull requests that fix identified bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants