From b7e881f8fa17b6047653f15c6678063869b68c7d Mon Sep 17 00:00:00 2001 From: Ryan May Date: Mon, 30 Mar 2020 18:32:09 -0600 Subject: [PATCH] Don't change Figure DPI if value unchanged Check that the value of dpi is different before going through all the machinery to actually flush the change of value. --- lib/matplotlib/figure.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 69b22df4528d..ea908f7ce897 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -442,11 +442,12 @@ def _set_dpi(self, dpi, forward=True): forward : bool Passed on to `~.Figure.set_size_inches` """ - self._dpi = dpi - self.dpi_scale_trans.clear().scale(dpi) - w, h = self.get_size_inches() - self.set_size_inches(w, h, forward=forward) - self.callbacks.process('dpi_changed', self) + if self._dpi != dpi: + self._dpi = dpi + self.dpi_scale_trans.clear().scale(dpi) + w, h = self.get_size_inches() + self.set_size_inches(w, h, forward=forward) + self.callbacks.process('dpi_changed', self) dpi = property(_get_dpi, _set_dpi, doc="The resolution in dots per inch.")