Skip to content

Move pixel ratio handling into FigureCanvasBase #19126

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

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Dec 16, 2020

PR Summary

This is already implemented in two backends (Qt5 and nbAgg), and I plan to implement it in TkAgg, so it's better to remove the repetition.

It may also be useful for external backends.

I haven't fully tested this yet (though the test suite passes), as it's waiting for #19083 and #19123.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [?] New features are documented, with examples if plot related.
  • 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).

@dopplershift
Copy link
Contributor

I wonder if this will make #18274 work better (with adjustments there as well)

@QuLogic QuLogic marked this pull request as ready for review December 19, 2020 06:08
@QuLogic QuLogic force-pushed the hidpi-refactor branch 4 times, most recently from e5a840b to 3385d1a Compare December 25, 2020 00:31
@QuLogic
Copy link
Member Author

QuLogic commented Dec 25, 2020

OK, I renamed it, and also made the setter return whether the ratio changed; it seems common in backends to do something in such cases, so that removes some code from all of them.

self.figure._original_dpi = self.figure.dpi
self.figure.dpi = dpi_ratio * self.figure._original_dpi
self._dpi_ratio = dpi_ratio
def handle_set_device_pixel_ratio(self, event):
Copy link
Contributor

@anntzer anntzer Feb 10, 2021

Choose a reason for hiding this comment

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

I guess these handlers are effectively private and we reserve the right to change them as we see fit with no deprecation?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point, but I would say so. They're tied directly with the JavaScript side of the implementation, and I don't think we've ever guaranteed anything there.

In this case, it's only a rename for consistency's sake, so I could revert it.

Copy link
Member

Choose a reason for hiding this comment

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

This will likely require a change in ipympl, but I think we should make the changes to keep the function names consistent (in this case).

Copy link
Member Author

Choose a reason for hiding this comment

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

I restored the handler for set_dpi_ratio, as then one can continue using an older version of ipympl with the new Matplotlib that comes out with this change.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Just one minor point about public/private API.

@QuLogic QuLogic added this to the v3.5.0 milestone Apr 1, 2021
QuLogic added a commit to QuLogic/ipympl that referenced this pull request Apr 6, 2021
QuLogic added a commit to QuLogic/ipympl that referenced this pull request Apr 6, 2021
@QuLogic QuLogic linked an issue Apr 6, 2021 that may be closed by this pull request
This is already implemented in two backends (Qt5 and nbAgg), and I plan
to implement it in TkAgg, so it's better to remove the repetition.
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

@QuLogic can merge on green.

@QuLogic QuLogic merged commit a61f208 into matplotlib:master Apr 8, 2021
@QuLogic QuLogic deleted the hidpi-refactor branch April 8, 2021 04:00
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Oct 15, 2021
This was not originally implemented in matplotlib#19126, but causes some
inconsistencies with other backends.

This also sets the initial scale as implemented in matplotlib#18274.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Oct 15, 2021
This was not originally implemented in matplotlib#19126, but causes some
inconsistencies with other backends.

This also sets the initial scale as implemented in matplotlib#18274.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Oct 20, 2021
This was not originally implemented in matplotlib#19126, but causes some
inconsistencies with other backends.

This also sets the initial scale as implemented in matplotlib#18274.
ccaprani pushed a commit to ccaprani/matplotlib that referenced this pull request Jan 23, 2023
This was not originally implemented in matplotlib#19126, but causes some
inconsistencies with other backends.

This also sets the initial scale as implemented in matplotlib#18274.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add HiDPI physical to logical pixel ratio property
5 participants