Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ def __init__(self, figure=None):
self.toolbar = None # NavigationToolbar2 will set me
self._is_idle_drawing = False
# We don't want to scale up the figure DPI more than once.
figure._original_dpi = figure.dpi
figure._original_dpi = getattr(figure, '_original_dpi', figure.dpi)
self._device_pixel_ratio = 1
super().__init__() # Typically the GUI widget init (if any).

Expand Down
13 changes: 6 additions & 7 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3003,12 +3003,10 @@ def _set_base_canvas(self):
This is used upon initialization of the Figure, but also
to reset the canvas when decoupling from pyplot.
"""
# check if we have changed the DPI due to hi-dpi screens
orig_dpi = getattr(self, '_original_dpi', self._dpi)
FigureCanvasBase(self) # Set self.canvas as a side-effect
# put it back to what it was
if orig_dpi != self._dpi:
self.dpi = orig_dpi
# undo any high-dpi scaling
if self._dpi != self._original_dpi:
self.dpi = self._original_dpi

def set_canvas(self, canvas):
"""
Expand Down Expand Up @@ -3323,8 +3321,9 @@ def __setstate__(self, state):
self.__dict__ = state

# re-initialise some of the unstored state information
FigureCanvasBase(self) # Set self.canvas.

self._set_base_canvas()
# force the bounding boxes to respect current dpi
self.dpi_scale_trans.clear().scale(self._dpi)
if restore_to_pylab:
# lazy import to avoid circularity
import matplotlib.pyplot as plt
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,9 @@ def test_unpickle_with_device_pixel_ratio():
assert fig.dpi == 42*7
fig2 = pickle.loads(pickle.dumps(fig))
assert fig2.dpi == 42
assert all(
[orig / 7 == restore for orig, restore in zip(fig.bbox.max, fig2.bbox.max)]
)


def test_gridspec_no_mutate_input():
Expand Down