|
| 1 | +from __future__ import annotations |
| 2 | +from typing import Literal |
| 3 | + |
1 | 4 | import numpy as np
|
2 | 5 | import matplotlib as mpl
|
| 6 | +from matplotlib.figure import Figure |
3 | 7 | from seaborn.utils import _version_predates
|
4 | 8 |
|
5 | 9 |
|
@@ -144,19 +148,31 @@ def register_colormap(name, cmap):
|
144 | 148 | mpl.cm.register_cmap(name, cmap)
|
145 | 149 |
|
146 | 150 |
|
147 |
| -def set_layout_engine(fig, engine): |
| 151 | +def set_layout_engine( |
| 152 | + fig: Figure, |
| 153 | + engine: Literal["constrained", "compressed", "tight", "none"], |
| 154 | +) -> None: |
148 | 155 | """Handle changes to auto layout engine interface in 3.6"""
|
149 | 156 | if hasattr(fig, "set_layout_engine"):
|
150 | 157 | fig.set_layout_engine(engine)
|
151 | 158 | else:
|
152 | 159 | # _version_predates(mpl, 3.6)
|
153 | 160 | if engine == "tight":
|
154 |
| - fig.set_tight_layout(True) |
| 161 | + fig.set_tight_layout(True) # type: ignore # predates typing |
155 | 162 | elif engine == "constrained":
|
156 |
| - fig.set_constrained_layout(True) |
| 163 | + fig.set_constrained_layout(True) # type: ignore |
157 | 164 | elif engine == "none":
|
158 |
| - fig.set_tight_layout(False) |
159 |
| - fig.set_constrained_layout(False) |
| 165 | + fig.set_tight_layout(False) # type: ignore |
| 166 | + fig.set_constrained_layout(False) # type: ignore |
| 167 | + |
| 168 | + |
| 169 | +def get_layout_engine(fig: Figure) -> mpl.layout_engine.LayoutEngine | None: |
| 170 | + """Handle changes to auto layout engine interface in 3.6""" |
| 171 | + if hasattr(fig, "get_layout_engine"): |
| 172 | + return fig.get_layout_engine() |
| 173 | + else: |
| 174 | + # _version_predates(mpl, 3.6) |
| 175 | + return None |
160 | 176 |
|
161 | 177 |
|
162 | 178 | def share_axis(ax0, ax1, which):
|
|
0 commit comments