Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
tacaswell committed Apr 17, 2017
commit d739943d85133a9e363ff8560e62ab3e978529f4
22 changes: 13 additions & 9 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ def __init__(self,
if frameon is None:
frameon = rcParams['figure.frameon']

self.dpi_scale_trans = Affine2D()
self.dpi = dpi
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
self.dpi_scale_trans = Affine2D().scale(dpi, dpi)
# do not use property as it will trigger
self._dpi = dpi
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)

self.frameon = frameon
Expand Down Expand Up @@ -413,6 +414,7 @@ def _get_dpi(self):
def _set_dpi(self, dpi):
self._dpi = dpi
self.dpi_scale_trans.clear().scale(dpi, dpi)
self.set_size_inches(*self.get_size_inches())
self.callbacks.process('dpi_changed', self)
dpi = property(_get_dpi, _set_dpi)

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

if forward:
ratio = getattr(self.canvas, '_dpi_ratio', 1)
dpival = self.dpi / ratio
canvasw = w * dpival
canvash = h * dpival
manager = getattr(self.canvas, 'manager', None)
if manager is not None:
manager.resize(int(canvasw), int(canvash))
canvas = getattr(self, 'canvas')
if canvas is not None:
ratio = getattr(self.canvas, '_dpi_ratio', 1)
dpival = self.dpi / ratio
canvasw = w * dpival
canvash = h * dpival
manager = getattr(self.canvas, 'manager', None)
if manager is not None:
manager.resize(int(canvasw), int(canvash))
self.stale = True

def get_size_inches(self):
Expand Down