From af13bd5ede4b32ff8c0265b477adeac9c568f4a8 Mon Sep 17 00:00:00 2001 From: "Albert Y. Shih" Date: Mon, 18 May 2026 12:20:12 -0400 Subject: [PATCH] Fix floating-point precision affecting gridspec bottom and right --- lib/matplotlib/gridspec.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index 5cd05bc167bb..e6f6f6fefa71 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -187,6 +187,11 @@ def get_grid_positions(self, fig): fig_tops, fig_bottoms = (top - cell_hs).reshape((-1, 2)).T fig_lefts, fig_rights = (left + cell_ws).reshape((-1, 2)).T + + # avoid floating-point precision where A + (B - A) does not equal B + fig_bottoms[-1] = bottom + fig_rights[-1] = right + return fig_bottoms, fig_tops, fig_lefts, fig_rights @staticmethod