Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd7c2e0

Browse files
committed
ENH: add a NullLayoutEngine
It can mirror what ever was there to make sure things stay compatible.
1 parentbf8a992 commitdd7c2e0

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-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
frommatplotlib.axesimportAxes,SubplotBase,subplot_class_factory
3737
frommatplotlib.gridspecimportGridSpec
38-
frommatplotlib.layout_engineimport (ConstrainedLayoutEngine,
39-
TightLayoutEngine,LayoutEngine)
38+
frommatplotlib.layout_engineimport (
39+
ConstrainedLayoutEngine,TightLayoutEngine,LayoutEngine,NullLayoutEnigne
40+
)
4041
importmatplotlib.legendasmlegend
4142
frommatplotlib.patchesimportRectangle
4243
frommatplotlib.textimportText
@@ -2356,7 +2357,13 @@ def set_layout_engine(self, layout=None, **kwargs):
23562357
eliflayout=='constrained':
23572358
new_layout_engine=ConstrainedLayoutEngine(**kwargs)
23582359
eliflayout=='none':
2359-
new_layout_engine=None
2360+
ifself._layout_engineisnotNone:
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
elifisinstance(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
raiseNotImplementedError
102102

103103

104+
classNullLayoutEnigne(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+
defexecute(self,fig):
123+
return
124+
125+
104126
classTightLayoutEngine(LayoutEngine):
105127
"""
106128
Implements the ``tight_layout`` geometry management. See

‎lib/matplotlib/tests/test_figure.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
frommatplotlib.axesimportAxes
1919
frommatplotlib.figureimportFigure
2020
frommatplotlib.layout_engineimport (ConstrainedLayoutEngine,
21-
TightLayoutEngine)
21+
TightLayoutEngine,
22+
NullLayoutEnigne)
2223
frommatplotlib.tickerimportAutoMinorLocator,FixedFormatter,ScalarFormatter
2324
importmatplotlib.pyplotasplt
2425
importmatplotlib.datesasmdates
@@ -610,17 +611,23 @@ def test_invalid_layouts():
610611
fig,ax=plt.subplots(layout="constrained")
611612
pc=ax.pcolormesh(np.random.randn(2,2))
612613
fig.colorbar(pc)
614+
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
615+
fig.set_layout_engine("tight")
616+
fig.set_layout_engine("none")
613617
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
614618
fig.set_layout_engine("tight")
615619

616620
fig,ax=plt.subplots(layout="tight")
617621
pc=ax.pcolormesh(np.random.randn(2,2))
618622
fig.colorbar(pc)
623+
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
624+
fig.set_layout_engine("constrained")
625+
fig.set_layout_engine("none")
619626
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
620627
fig.set_layout_engine("constrained")
621628

622629
fig.set_layout_engine("none")
623-
assertfig.get_layout_engine()isNone
630+
assertisinstance(fig.get_layout_engine(),NullLayoutEnigne)
624631

625632

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp