Skip to content

Commit 9195a88

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 aad1619 commit 9195a88

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

17051705
subplotspec_list = get_subplotspec_list(self.axes)
1706-
if None in subplotspec_list:
1707-
warnings.warn("This figure includes Axes that are not "
1708-
"compatible with tight_layout, so its "
1709-
"results might be incorrect.")
17101706

17111707
if renderer is None:
17121708
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy