Skip to content

Commit 701ae74

Browse files
committed
API: feedback to figure size due to pixel counts
When rasterizing the figure, the allowed sizes are discrete due to a finite dpi. When getting the renderer (at which point we have committed to rasterizing the figure at this dpi) feedback the actual size.
1 parent 80a7a02 commit 701ae74

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ def draw(self):
405405
@_api.delete_parameter("3.6", "cleared", alternative="renderer.clear()")
406406
def get_renderer(self, cleared=False):
407407
w, h = np.round(self.figure.bbox.size).astype(int)
408+
dpi = self.figure.dpi
409+
410+
# we know we are using Agg, thus are tied to discrete sizes
411+
# set by the dpi. Feed this back so that the transforms are
412+
# mapped to the available pixels
413+
self.figure.set_size_inches(w / dpi, h / dpi)
414+
408415
key = w, h, self.figure.dpi
409416
reuse_renderer = (self._lastKey == key)
410417
if not reuse_renderer:

0 commit comments

Comments
 (0)