Skip to content

FIX: round instead of truncate Agg canvas size #8265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
tacaswell committed Dec 5, 2022
commit 701ae74b8060efea436ec9bd9f60407fddc68b3f
7 changes: 7 additions & 0 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ def draw(self):
@_api.delete_parameter("3.6", "cleared", alternative="renderer.clear()")
def get_renderer(self, cleared=False):
w, h = np.round(self.figure.bbox.size).astype(int)
dpi = self.figure.dpi

# we know we are using Agg, thus are tied to discrete sizes
# set by the dpi. Feed this back so that the transforms are
# mapped to the available pixels
self.figure.set_size_inches(w / dpi, h / dpi)

key = w, h, self.figure.dpi
reuse_renderer = (self._lastKey == key)
if not reuse_renderer:
Expand Down