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

Skip to content

Commit 776c940

Browse files
committed
Update figure DPI when dpi_ratio changes
We do this by setting _dpi rather than using the dpi property since we want to avoid any resizing and callbacks.
1 parent f8cb5c9 commit 776c940

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def paintEvent(self, e):
6868
# As described in __init__ above, we need to be careful in cases with
6969
# mixed resolution displays if dpi_ratio is changing between painting
7070
# events.
71-
if self._dpi_ratio_prev is None:
72-
self._dpi_ratio_prev = self._dpi_ratio
73-
elif self._dpi_ratio != self._dpi_ratio_prev:
71+
if self._dpi_ratio_prev or self._dpi_ratio != self._dpi_ratio_prev:
72+
# We need to update the figure DPI
73+
self._update_figure_dpi()
7474
# The easiest way to resize the canvas is to emit a resizeEvent
7575
# since we implement all the logic for resizing the canvas for
7676
# that event.
@@ -196,6 +196,11 @@ def __init__(self, figure):
196196
self.figure._original_dpi = self.figure.dpi
197197
self.figure.dpi = self._dpi_ratio * self.figure._original_dpi
198198

199+
def _update_figure_dpi(self):
200+
dpi = self._dpi_ratio * self.figure._original_dpi
201+
self.figure._dpi = dpi
202+
self.figure.dpi_scale_trans.clear().scale(dpi, dpi)
203+
199204

200205
@_BackendQT5.export
201206
class _BackendQT5Agg(_BackendQT5):

0 commit comments

Comments
 (0)