Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26ab2fc

Browse files
committed
Set device pixel ratio when saving a figure
Otherwise, `FigureCanvasBase.get_width_height` returns a size scaled down by the current pixel ratio, even though the DPI is not scaled up. This causes the saved figure to be cropped.
1 parent e371623 commit 26ab2fc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,7 @@ def print_figure(
22592259
# Remove the figure manager, if any, to avoid resizing the GUI widget.
22602260
with cbook._setattr_cm(self, manager=None), \
22612261
cbook._setattr_cm(self.figure, dpi=dpi), \
2262+
cbook._setattr_cm(canvas, _device_pixel_ratio=1), \
22622263
cbook._setattr_cm(canvas, _is_saving=True), \
22632264
ExitStack() as stack:
22642265

0 commit comments

Comments
 (0)