| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,8 +35,9 @@ | |||
| 35 | 35 | ||
| 36 | 36 | from matplotlib.axes import Axes, SubplotBase, subplot_class_factory | |
| 37 | 37 | 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 | + ) | ||
| 40 | 41 | import matplotlib.legend as mlegend | |
| 41 | 42 | from matplotlib.patches import Rectangle | |
| 42 | 43 | from matplotlib.text import Text | |
@@ -2356,7 +2357,13 @@ def set_layout_engine(self, layout=None, **kwargs): | |||
| 2356 | 2357 | elif layout == 'constrained': | |
| 2357 | 2358 | new_layout_engine = ConstrainedLayoutEngine(**kwargs) | |
| 2358 | 2359 | 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 | ||
| 2360 | 2367 | elif isinstance(layout, LayoutEngine): | |
| 2361 | 2368 | new_layout_engine = layout | |
| 2362 | 2369 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,6 +101,28 @@ def execute(self, fig): | |||
| 101 | 101 | raise NotImplementedError | |
| 102 | 102 | ||
| 103 | 103 | ||
| 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 | + | ||
| 104 | 126 | class TightLayoutEngine(LayoutEngine): | |
| 105 | 127 | """ | |
| 106 | 128 | Implements the ``tight_layout`` geometry management. See | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,8 @@ | |||
| 18 | 18 | from matplotlib.axes import Axes | |
| 19 | 19 | from matplotlib.figure import Figure | |
| 20 | 20 | from matplotlib.layout_engine import (ConstrainedLayoutEngine, | |
| 21 | - TightLayoutEngine) | ||
| 21 | + TightLayoutEngine, | ||
| 22 | + NullLayoutEnigne) | ||
| 22 | 23 | from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter | |
| 23 | 24 | import matplotlib.pyplot as plt | |
| 24 | 25 | import matplotlib.dates as mdates | |
@@ -610,17 +611,23 @@ def test_invalid_layouts(): | |||
| 610 | 611 | fig, ax = plt.subplots(layout="constrained") | |
| 611 | 612 | pc = ax.pcolormesh(np.random.randn(2, 2)) | |
| 612 | 613 | fig.colorbar(pc) | |
| 614 | + with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): | ||
| 615 | + fig.set_layout_engine("tight") | ||
| 616 | + fig.set_layout_engine("none") | ||
| 613 | 617 | with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): | |
| 614 | 618 | fig.set_layout_engine("tight") | |
| 615 | 619 | ||
| 616 | 620 | fig, ax = plt.subplots(layout="tight") | |
| 617 | 621 | pc = ax.pcolormesh(np.random.randn(2, 2)) | |
| 618 | 622 | fig.colorbar(pc) | |
| 623 | + with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): | ||
| 624 | + fig.set_layout_engine("constrained") | ||
| 625 | + fig.set_layout_engine("none") | ||
| 619 | 626 | with pytest.raises(RuntimeError, match='Colorbar layout of new layout'): | |
| 620 | 627 | fig.set_layout_engine("constrained") | |
| 621 | 628 | ||
| 622 | 629 | fig.set_layout_engine("none") | |
| 623 | - assert fig.get_layout_engine() is None | ||
| 630 | + assert isinstance(fig.get_layout_engine(), NullLayoutEnigne) | ||
| 624 | 631 | ||
| 625 | 632 | ||
| 626 | 633 | @check_figures_equal(extensions=["png", "pdf"]) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments