8000 tight_layout: Use a different default gridspec · matplotlib/matplotlib@09989b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 09989b7

Browse files
committed
tight_layout: Use a different default gridspec
This commit adds a default gridspec to tight_layout. It helps to build a better wimage when using tight_layout with figures that do not (yet) implement their own gridspec. This does not affect figures that do not use tight_layout and only improves the case with tight_layout at least in my testcases. The warning, that warns from the usage of figures that have no gridspec implemented is retained.
1 parent b580c07 commit 09989b7

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

lib/matplotlib/figure.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,10 +1865,6 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None,
18651865
get_subplotspec_list)
18661866

18671867
subplotspec_list = get_subplotspec_list(self.axes)
1868-
if None in subplotspec_list:
1869-
warnings.warn("This figure includes Axes that are not "
1870-
"compatible with tight_layout, so its "
1871-
"results might be incorrect.")
18721868

18731869
if renderer is None:
18741870
renderer = get_renderer(self)

lib/matplotlib/gridspec.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,6 @@ def tight_layout(self, fig, renderer=None, pad=1.08, h_pad=None, w_pad=None, rec
302302
get_renderer)
303303

304304
subplotspec_list = get_subplotspec_list(fig.axes, grid_spec=self)
305-
if None in subplotspec_list:
306-
warnings.warn("This figure includes Axes that are not "
307-
"compatible with tight_layout, so its "
308-
"results might be incorrect.")
309305

310306
if renderer is None:
311307
renderer = get_renderer(fig)

lib/matplotlib/tight_layout.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import warnings
1313

1414
import matplotlib
15+
import matplotlib.gridspec as gridspec
1516
from matplotlib.transforms import TransformedBbox, Bbox
1617

1718
from matplotlib.font_manager import FontProperties
@@ -233,8 +234,8 @@ def get_subplotspec_list(axes_list, grid_spec=None):
233234
instance of axes that does not support subplotspec, None is
234235
inserted in the list.
235236
236-
If grid_spec is given, None is inserted for those not from
237-
the given grid_spec.
237+
If grid_spec is given, GridSpec(1, 1) is inserted and a warning emited for
238+
those not from the given grid_spec.
238239
239240
"""
240241
subplotspec_list = []
@@ -253,7 +254,10 @@ def get_subplotspec_list(axes_list, grid_spec=None):
253254
elif gs.locally_modified_subplot_params():
254255
subplotspec = None
255256
else:
256-
subplotspec = None
257+
warnings.warn("This figure includes Axes that are not "
258+
"compatible with tight_layout, so its "
259+
"results might be incorrect.")
260+
subplotspec = gridspec.GridSpec(1, 1)
257261

258262
subplotspec_list.append(subplotspec)
259263

0 commit comments

Comments
 (0)
0