Skip to content

Commit 973c99e

Browse files
committed
FIX: correctly restore the size of unpickled figures with hi-dpi
The issue is that we reset the dpi but did not re-compute any of the bounding boxes derived from the dpi leading to the initial redraw events to use the wrong physical size on the screen. Closes matplotlib#27224
1 parent c0041fb commit 973c99e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,8 +3321,9 @@ def __setstate__(self, state):
33213321
self.__dict__ = state
33223322

33233323
# re-initialise some of the unstored state information
3324-
FigureCanvasBase(self) # Set self.canvas.
3325-
3324+
self._set_base_canvas()
3325+
# force the bounding boxes to respect current dpi
3326+
self.dpi_scale_trans.clear().scale(self._dpi)
33263327
if restore_to_pylab:
33273328
# lazy import to avoid circularity
33283329
import matplotlib.pyplot as plt

lib/matplotlib/tests/test_figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,9 @@ def test_unpickle_with_device_pixel_ratio():
16881688
assert fig.dpi == 42*7
16891689
fig2 = pickle.loads(pickle.dumps(fig))
16901690
assert fig2.dpi == 42
1691+
assert all(
1692+
[orig / 7 == restore for orig, restore in zip(fig.bbox.max, fig2.bbox.max)]
1693+
)
16911694

16921695

16931696
def test_gridspec_no_mutate_input():

0 commit comments

Comments
 (0)