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

Skip to content

Commit fdffd7c

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 fe701e3 commit fdffd7c

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
@@ -1873,10 +1873,6 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None,
18731873
get_subplotspec_list)
18741874

18751875
subplotspec_list = get_subplotspec_list(self.axes)
1876-
if None in subplotspec_list:
1877-
warnings.warn("This figure includes Axes that are not "
1878-
"compatible with tight_layout, so its "
1879-
"results might be incorrect.")
18801876

18811877
if renderer is None:
18821878
renderer = get_renderer(self)

lib/matplotlib/gridspec.py

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

300300
subplotspec_list = get_subplotspec_list(fig.axes, grid_spec=self)
301-
if None in subplotspec_list:
302-
warnings.warn("This figure includes Axes that are not "
303-
"compatible with tight_layout, so its "
304-
"results might be incorrect.")
305301

306302
if renderer is None:
307303
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