Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4ebfe4

Browse filesBrowse files
authored
Merge pull request #9164 from jklymak/fixgettightbox
include overspilling axes legends in ax.get_tightbbox
2 parents a57d436 + fc04c62 commit d4ebfe4
Copy full SHA for d4ebfe4

File tree

Expand file treeCollapse file tree

2 files changed

+10
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-0
lines changed
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Axes legends now included in tight_bbox
2+
---------------------------------------
3+
4+
Legends created via ``ax.legend()`` can sometimes overspill the limits of
5+
the axis. Tools like ``fig.tight_layout()`` and
6+
``fig.savefig(bbox_inches='tight')`` would clip these legends. A change
7+
was made to include them in the ``tight`` calculations.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import matplotlib.image as mimage
3434
from matplotlib.offsetbox import OffsetBox
3535
from matplotlib.artist import allow_rasterization
36+
from matplotlib.legend import Legend
3637

3738
from matplotlib.rcsetup import cycler
3839
from matplotlib.rcsetup import validate_axisbelow
@@ -3969,6 +3970,8 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
39693970
for child in self.get_children():
39703971
if isinstance(child, OffsetBox) and child.get_visible():
39713972
bb.append(child.get_window_extent(renderer))
3973+
elif isinstance(child, Legend) and child.get_visible():
3974+
bb.append(child._legend_box.get_window_extent(renderer))
39723975

39733976
_bbox = mtransforms.Bbox.union(
39743977
[b for b in bb if b.width != 0 or b.height != 0])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.