Skip to content

Commit 8d78315

Browse files
committed
Support returning physical size of the canvas.
1 parent 3730b9e commit 8d78315

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
@@ -2094,17 +2094,24 @@ def _set_device_pixel_ratio(self, ratio):
20942094
self._device_pixel_ratio = ratio
20952095
return True
20962096

2097-
def get_width_height(self):
2097+
def get_width_height(self, physical=False):
20982098
"""
20992099
Return the figure width and height in integral points or pixels.
21002100
2101+
Parameters
2102+
----------
2103+
physical : bool, default: False
2104+
Whether to return true physical pixels or logical pixels. Physical
2105+
pixels may be used by backends that support HiDPI, but still
2106+
configure the canvas using its actual size.
2107+
21012108
Returns
21022109
-------
21032110
width, height : int
21042111
The size of the figure, in points or pixels, depending on the
21052112
backend.
21062113
"""
2107-
return tuple(int(size / self.device_pixel_ratio)
2114+
return tuple(int(size / (1 if physical else self.device_pixel_ratio))
21082115
for size in self.figure.bbox.max)
21092116

21102117
@classmethod

0 commit comments

Comments
 (0)