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

Skip to content

Commit b151072

Browse files
committed
Support returning physical size of the canvas.
1 parent 393c3af commit b151072

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/matplotlib/backend_bases.py

Li 8000 nes changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,17 +2080,24 @@ def _set_device_pixel_ratio(self, ratio):
20802080
self.figure._set_dpi(dpi, forward=False)
20812081
self._device_pixel_ratio = ratio
20822082

2083-
def get_width_height(self):
2083+
def get_width_height(self, physical=False):
20842084
"""
20852085
Return the figure width and height in integral points or pixels.
20862086
2087+
Parameters
2088+
----------
2089+
physical : bool, default: False
2090+
Whether to return true physical pixels or logical pixels. Physical
2091+
pixels may be used by backends that support HiDPI, but still
2092+
configure the canvas using its actual size.
2093+
20872094
Returns
20882095
-------
20892096
width, height : int
20902097
The size of the figure, in points or pixels, depending on the
20912098
backend.
20922099
"""
2093-
return tuple(int(size / self.device_pixel_ratio)
2100+
return tuple(int(size / (1 if physical else self.device_pixel_ratio))
20942101
for size in self.figure.bbox.max)
20952102

20962103
@classmethod

0 commit comments

Comments
 (0)
0