Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa2a746

Browse files
committed
ENH: add a NullLayoutEngine
It can mirror what ever was there to make sure things stay compatible.
1 parent bf8a992 commit aa2a746

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lib/matplotlib/figure.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535

3636
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
3737
from matplotlib.gridspec import GridSpec
38-
from matplotlib.layout_engine import (ConstrainedLayoutEngine,
39-
TightLayoutEngine, LayoutEngine)
38+
from matplotlib.layout_engine import (
39+
ConstrainedLayoutEngine,TightLayoutEngine, LayoutEngine, NullLayoutEnigne
40+
)
4041
import matplotlib.legend as mlegend
4142
from matplotlib.patches import Rectangle
4243
from matplotlib.text import Text
@@ -2356,7 +2357,13 @@ def set_layout_engine(self, layout=None, **kwargs):
23562357
elif layout == 'constrained':
23572358
new_layout_engine = ConstrainedLayoutEngine(**kwargs)
23582359
elif layout == 'none':
2359-
new_layout_engine = None
2360+
if self._layout_engine is not None:
2361+
new_layout_engine = NullLayoutEnigne(
2362+
self._layout_engine.adjust_compatible,
2363+
self._layout_engine.colorbar_gridspec
2364+
)
2365+
else:
2366+
new_layout_engine = None
23602367
elif isinstance(layout, LayoutEngine):
23612368
new_layout_engine = layout
23622369
else:

lib/matplotlib/layout_engine.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ def execute(self, fig):
101101
raise NotImplementedError
102102

103103

104+
class NullLayoutEnigne(LayoutEngine):
105+
"""
106+
A no-op LayoutEngine.
107+
108+
This is primarily to act as a place holder if we remove a layout engine.
109+
110+
Parameter
111+
---------
112+
adjust_compatible, colorbar_gridspec : bool
113+
Allow the NullLayoutEnigne to mirror the behavior of whatever
114+
layout engine it is replacing.
115+
116+
"""
117+
def __init__(self, adjust_compatible, colorbar_gridspec, **kwargs):
118+
self._adjust_compatible = adjust_compatible
119+
self._colorbar_gridspec = colorbar_gridspec
120+
super().__init__(**kwargs)
121+
122+
def execute(self, fig):
123+
return
124+
125+
104126
class TightLayoutEngine(LayoutEngine):
105127
"""
106128
Implements the ``tight_layout`` geometry management. See

lib/matplotlib/tests/test_figure.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
from matplotlib.axes import Axes
1919
from matplotlib.figure import Figure
2020
from matplotlib.layout_engine import (ConstrainedLayoutEngine,
21-
TightLayoutEngine)
21+
TightLayoutEngine,
22+
NullLayoutEnigne)
2223
from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter
2324
import matplotlib.pyplot as plt
2425
import matplotlib.dates as mdates
@@ -620,7 +621,7 @@ def test_invalid_layouts():
620621
fig.set_layout_engine("constrained")
621622

622623
fig.set_layout_engine("none")
623-
assert fig.get_layout_engine() is None
624+
assert isinstance(fig.get_layout_engine(), NullLayoutEnigne)
624625

625626

626627
@check_figures_equal(extensions=["png", "pdf"])

0 commit comments

Comments
 (0)