Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 5 commits into from
Feb 27, 2018

Conversation

AlexHarn
Copy link
Contributor

@AlexHarn AlexHarn commented Feb 22, 2018

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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jkseppan
Copy link
Member

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()
Copy link
Member

@timhoffm timhoffm Feb 24, 2018

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

Copy link
Contributor

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:
Copy link
Member

Choose a reason for hiding this comment

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

Indentation error

Copy link
Contributor Author

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...

@timhoffm timhoffm merged commit f9b67a4 into matplotlib:master Feb 27, 2018
@tacaswell
Copy link
Member

@meeseeksdev backport to v2.2.x

@tacaswell tacaswell added this to the v2.2.0 milestone Feb 28, 2018
lumberbot-app bot pushed a commit that referenced this pull request Feb 28, 2018
anntzer added a commit that referenced this pull request Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants