-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Prevent ZeroDivisionError when devicePixelRatio() returns 0 #10568
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
I'm not sure I understand the underlying issue, but it does seem that a ratio of 0 makes no sense here, so returning 1 is better. |
@@ -269,7 +269,11 @@ def _update_figure_dpi(self): | |||
def _dpi_ratio(self): | |||
# Not available on Qt4 or some older Qt5. | |||
try: | |||
return self.devicePixelRatio() | |||
ratio = self.devicePixelRatio() |
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.
simpler: return self.devicePixelRatio() or 1 # can be 0 in rare cases
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.
a comment would be nice, indeed.
* upstream/master: (42 commits) More style fixes. Remove more subprocess imports Add API note Bump a tolerance in test_axisartist_floating_axes. Minor style fixes. TST: colorbar check for constrained layout FIX: colorbar check for constrained layout Use 'yield from' where appropriate. Various style fixes. Remove some str() calls not needed on py3 Add subprocess deprecation message PEP8 fix for continuation of the line bugfix in axes3d Changed to "five" rcParams Might be `figure.constrained_layout.use` add a test use orientation value from kwargs Minor simplification to Figure.__getstate__ logic. Remove alternative for ispower2 Switch internal subprocess calls to python stdlib ...
return 1 | ||
else: | ||
return ratio | ||
try: |
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.
Indentation 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.
I'm sorry, I should have double checked that...
@meeseeksdev backport to v2.2.x |
Backport PR #10568 on branch v2.2.x
This bug only occurs under very special circumstances. For some reason when using Screen Scaling in KDE while also downscaling the terminal emulator Konsole, in which matplotlib is run, devicePixelRatio() returns 0 and causes a ZeroDevisionError. I do not know other circumstances under which this bug occurs. It is also probably not really a bug in matplotlib, but this fixes the issue for me.
You may ask why this setup is necessary to begin with, the answer can be found here. Essentially it is a workaround necessary to prevent screen tearing in Konsole for some very few people including myself.
PR Summary
PR Checklist