8000 Handle handle empty figures in tight_layout (#8891) · matplotlib/matplotlib@c2f3788 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2f3788

Browse files
Molly Rossow
8000
QuLogic
authored andcommitted
Handle handle empty figures in tight_layout (#8891)
* Fix tight_layout to handle empty figures * Fix formatting * Change tight_layout to always return a dictionary
1 parent a6ceb3b commit c2f3788

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,12 @@ def _subplots():
264264
child.set_visible(False)
265265

266266
plt.tight_layout()
267+
268+
269+
def test_empty_layout():
270+
"""Tests that tight layout doesn't cause an error when there are
271+
no axes.
272+
"""
273+
274+
fig = plt.gcf()
275+
fig.tight_layout()

lib/matplotlib/tight_layout.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
319319

320320
subplots.append(ax)
321321

322+
if (len(nrows_list) == 0) or (len(ncols_list) == 0):
323+
return {}
324+
322325
max_nrows = max(nrows_list)
323326
max_ncols = max(ncols_list)
324327

0 commit comments

Comments
 (0)
0