-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix scaling in Tk on non-Windows systems #28588
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
Conversation
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 week or so, please leave a new comment below and that should bring it to our attention. 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.
ping |
Thank you for the ping! attn @richardsheridan as our Tk expert. |
This needs to be tested manually on Linux with two monitors with different dpi or scaling. I can't help with that though! |
I took the screenshots of the windows of the same plot at about the same physical dimensions on two different screens. I tested everything on GNU/Linux with X.org. Someone should try a Wayland compositor and maybe macOS. |
Thanks for the comparison images. Positioning looks correct. I can't tell for the linewidths. Obviously, that depends on the upscaling. Probably an additional helpful comparison would be hidpi Qt backend vs hidpi Tk backend. I'd expect that the plot area would be pixel identical if we properly detect hidpi/magnification and feed it to the agg renderer. |
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.
The scaling looks right, and if the window maintains about the same real-world dimensions when you drag it between monitors with different dpi, then I think it is good to go.
There are two Tk tests on MacOS failing. I'm unclear whether this is related to the PR. |
It doesn't for me, but for neither toolkit. When dragging the window from the 200dpi to 96dpi screen the physical dimensions increase (because my window manager doesn't really do anything about DPI) and the canvas remains scaled at 2x. |
I could not get to the build logs, but re-started the failed job. |
"power cycled" to get the tests to run again. |
Did anyone test this on macOS? If it's a concern I can enable it only for |
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.
While I cannot test on OSX, I'm very much convinced that the non-windows way is "more correct" than the windows specific solution - Linux and OSX are typically similar on those matters.
If nobody can test in the next couple of days, IMHO we should be bold enough to merge as is.
I tested this on osx and it looks good locally to me. There are failing tests on osx with the tkagg backend which seem like they could be related. |
We can also be more defensive and only change for linux as proposed above and then create a followup issue to investigate OSX. It would be good to have at least the linux version included in 3.10. |
The test failure is real and we can reproduce it locally. Debugging on a mac, it seems that
in between the calls I changed the resolution OSX was using. I think we need to exclude OSX here as this method does not actually work there as it tries to "help" a bit too much. |
# scaled vs 96 dpi, and pixel ratio settings are given in whole | ||
# percentages, so round to 2 digits. | ||
ratio = round(self._tkcanvas.tk.call('tk', 'scaling') / (96 / 72), 2) | ||
else: |
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.
else: | |
elif sys.platform == "linux": |
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 testing it out! I limited the change to just "linux" and made sure _set_device_pixel_ratio
is called only on supported platforms.
Thanks @rnhmjoj! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
Thank you all for reviewing my patch! |
PR summary
Fix scaling in Tk on non-Windows systems, closes #10388
PR checklist
cc: @tacaswell