|
| 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 |
|
@@ -84,19 +88,31 @@ def register_colormap(name, cmap):
|
84 | 88 | mpl.cm.register_cmap(name, cmap)
|
85 | 89 |
|
86 | 90 |
|
87 |
| -def set_layout_engine(fig, engine): |
| 91 | +def set_layout_engine( |
| 92 | + fig: Figure, |
| 93 | + engine: Literal["constrained", "compressed", "tight", "none"], |
| 94 | +) -> None: |
88 | 95 | """Handle changes to auto layout engine interface in 3.6"""
|
89 | 96 | if hasattr(fig, "set_layout_engine"):
|
90 | 97 | fig.set_layout_engine(engine)
|
91 | 98 | else:
|
92 | 99 | # _version_predates(mpl, 3.6)
|
93 | 100 | if engine == "tight":
|
94 |
| - fig.set_tight_layout(True) |
| 101 | + fig.set_tight_layout(True) # type: ignore # predates typing |
95 | 102 | elif engine == "constrained":
|
96 |
| - fig.set_constrained_layout(True) |
| 103 | + fig.set_constrained_layout(True) # type: ignore |
97 | 104 | elif engine == "none":
|
98 |
| - fig.set_tight_layout(False) |
99 |
| - fig.set_constrained_layout(False) |
| 105 | + fig.set_tight_layout(False) # type: ignore |
| 106 | + fig.set_constrained_layout(False) # type: ignore |
| 107 | + |
| 108 | + |
| 109 | +def get_layout_engine(fig: Figure) -> mpl.layout_engine.LayoutEngine | None: |
| 110 | + """Handle changes to auto layout engine interface in 3.6""" |
| 111 | + if hasattr(fig, "get_layout_engine"): |
| 112 | + return fig.get_layout_engine() |
| 113 | + else: |
| 114 | + # _version_predates(mpl, 3.6) |
| 115 | + return None |
100 | 116 |
|
101 | 117 |
|
102 | 118 | def share_axis(ax0, ax1, which):
|
|
0 commit comments