Skip to content

Commit d739943

Browse files
committed
ENH: setting the DPI properly propagates
Set the figure size back to the current value to push the dpi (and hence rendered size) change through.
1 parent 5a6826f commit d739943

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/matplotlib/figure.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,10 @@ def __init__(self,
323323
if frameon is None:
324324
frameon = rcParams['figure.frameon']
325325

326-
self.dpi_scale_trans = Affine2D()
327-
self.dpi = dpi
328326
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
327+
self.dpi_scale_trans = Affine2D().scale(dpi, dpi)
328+
# do not use property as it will trigger
329+
self._dpi = dpi
329330
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)
330331

331332
self.frameon = frameon
@@ -413,6 +414,7 @@ def _get_dpi(self):
413414
def _set_dpi(self, dpi):
414415
self._dpi = dpi
415416
self.dpi_scale_trans.clear().scale(dpi, dpi)
417+
self.set_size_inches(*self.get_size_inches())
416418
self.callbacks.process('dpi_changed', self)
417419
dpi = property(_get_dpi, _set_dpi)
418420

@@ -710,13 +712,15 @@ def set_size_inches(self, w, h=None, forward=True):
710712
self.bbox_inches.p1 = w, h
711713

712714
if forward:
713-
ratio = getattr(self.canvas, '_dpi_ratio', 1)
714-
dpival = self.dpi / ratio
715-
canvasw = w * dpival
716-
canvash = h * dpival
717-
manager = getattr(self.canvas, 'manager', None)
718-
if manager is not None:
719-
manager.resize(int(canvasw), int(canvash))
715+
canvas = getattr(self, 'canvas')
716+
if canvas is not None:
717+
ratio = getattr(self.canvas, '_dpi_ratio', 1)
718+
dpival = self.dpi / ratio
719+
canvasw = w * dpival
720+
canvash = h * dpival
721+
manager = getattr(self.canvas, 'manager', None)
722+
if manager is not None:
723+
manager.resize(int(canvasw), int(canvash))
720724
self.stale = True
721725

722726
def get_size_inches(self):

0 commit comments

Comments
 (0)