8000 Support returning physical size of the canvas. · matplotlib/matplotlib@f9ec6f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9ec6f8

Browse files
committed
Support returning physical size of the canvas.
1 parent 4c55250 commit f9ec6f8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,21 +2107,28 @@ def _set_device_pixel_ratio(self, ratio):
21072107
self._device_pixel_ratio = ratio
21082108
return True
21092109

2110-
def get_width_height(self):
2110+
def get_width_height(self, *, physical=False):
21112111
"""
21122112
Return the figure width and height in integral points or pixels.
21132113
21142114
When the figure is used on High DPI screens (and the backend supports
21152115
it), the truncation to integers occurs after scaling by the device
21162116
pixel ratio.
21172117
2118+
Parameters
2119+
----------
2120+
physical : bool, default: False
2121+
Whether to return true physical pixels or logical pixels. Physical
2122+
pixels may be used by backends that support HiDPI, but still
2123+
configure the canvas using its actual size.
2124+
21182125
Returns
21192126
-------
21202127
width, height : int
21212128
The size of the figure, in points or pixels, depending on the
21222129
backend.
21232130
"""
2124-
return tuple(int(size / self.device_pixel_ratio)
2131+
return tuple(int(size / (1 if physical else self.device_pixel_ratio))
21252132
for size in self.figure.bbox.max)
21262133

21272134
@classmethod

0 commit comments

Comments
 (0)
0