From 25d5c8be886025e8d6a2d9ce3244c3306dbf8658 Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Sat, 28 Jul 2018 18:40:05 -0700 Subject: [PATCH] Feature Add: In response to Issue #11764, re-factor of how Bbox class assigns padding in order to extend to non-symmetric padding on all sides. --- lib/matplotlib/backend_bases.py | 5 ++++- lib/matplotlib/transforms.py | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index ce15d9295fac..291ae7725e5d 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2055,7 +2055,10 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None, if pad is None: pad = rcParams['savefig.pad_inches'] - bbox_inches = bbox_inches.padded(pad) + if type(pad).__name__ == "tuple": + bbox_inches = bbox_inches.padded_lrtb(pad) + else: + bbox_inches = bbox_inches.padded(pad) restore_bbox = tight_bbox.adjust_bbox(self.figure, bbox_inches, canvas.fixed_dpi) diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 89942d87e319..5a46510b5cd9 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -692,7 +692,15 @@ def padded(self, p): the given value. """ points = self.get_points() - return Bbox(points + [[-p, -p], [p, p]]) + return self.padded_lrtb((p, p, p, p)) + + def padded_lrtb(self, lrtb): + """ + Return a new :class:`Bbox` that is padded with specific length + on all sides given by lrtb (4-tuple) + """ + points = self.get_points() + return Bbox(points + [[-lrtb[0], -lrtb[3]], [lrtb[1], lrtb[2]]]) def translated(self, tx, ty): """