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

Skip to content

Commit dca7536

Browse files
committed
Support returning physical size of the canvas.
1 parent d31a4cf commit dca7536

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
@@ -2108,21 +2108,28 @@ def _set_device_pixel_ratio(self, ratio):
21082108
self._device_pixel_ratio = ratio
21092109
return True
21102110

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

21282135
@classmethod

0 commit comments

Comments
 (0)
0