@@ -323,9 +323,10 @@ def __init__(self,
323
323
if frameon is None :
324
324
frameon = rcParams ['figure.frameon' ]
325
325
326
- self .dpi_scale_trans = Affine2D ()
327
- self .dpi = dpi
328
326
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
329
330
self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
330
331
331
332
self .frameon = frameon
@@ -413,6 +414,7 @@ def _get_dpi(self):
413
414
def _set_dpi (self , dpi ):
414
415
self ._dpi = dpi
415
416
self .dpi_scale_trans .clear ().scale (dpi , dpi )
417
+ self .set_size_inches (* self .get_size_inches ())
416
418
self .callbacks .process ('dpi_changed' , self )
417
419
dpi = property (_get_dpi , _set_dpi )
418
420
@@ -710,13 +712,15 @@ def set_size_inches(self, w, h=None, forward=True):
710
712
self .bbox_inches .p1 = w , h
711
713
712
714
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 ))
720
724
self .stale = True
721
725
722
726
def get_size_inches (self ):
0 commit comments