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

Skip to content

Commit 59380fa

Browse files
committed
Prevent ZeroDivisionError on plt.show() when devicePixelRatio() returns
0.
1 parent 9b48fd8 commit 59380fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ def _update_figure_dpi(self):
269269
def _dpi_ratio(self):
270270
# Not available on Qt4 or some older Qt5.
271271
try:
272-
return self.devicePixelRatio()
272+
ratio = self.devicePixelRatio()
273+
if ratio == 0:
274+
return 1
275+
else:
276+
return ratio
273277
except AttributeError:
274278
return 1
275279

0 commit comments

Comments
 (0)