Fix set_size_inches on HiDPI screens · matplotlib/matplotlib@7267d23 · GitHub
Skip to content

Commit 7267d23

Browse files
committed
Fix set_size_inches on HiDPI screens
This passes physical pixels to the backend, as it will be more accurate due to the int-cast. Fixes #21090
1 parent ef74de4 commit 7267d23

4 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ def set_window_title(self, title):
421421

422422
def resize(self, width, height):
423423
"""Set the canvas size in pixels."""
424+
width /= self.canvas.device_pixel_ratio
425+
height /= self.canvas.device_pixel_ratio
424426
if self.toolbar:
425427
toolbar_size = self.toolbar.size_request()
426428
height += toolbar_size.height

lib/matplotlib/backends/backend_gtk4.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ def set_window_title(self, title):
372372

373373
def resize(self, width, height):
374374
"""Set the canvas size in pixels."""
375+
width /= self.canvas.device_pixel_ratio
376+
height /= self.canvas.device_pixel_ratio
375377
if self.toolbar:
376378
min_size, nat_size = self.toolbar.get_preferred_size()
377379
height += nat_size.height

lib/matplotlib/figure.py

Lines changed: 1 addition & 2 deletions

0 commit comments

Comments
 (0)