Implements the ``constrained_layout`` geometry management. See :ref:`constrainedlayout_guide` for details.
| 214 | |
| 215 | |
| 216 | class ConstrainedLayoutEngine(LayoutEngine): |
| 217 | """ |
| 218 | Implements the ``constrained_layout`` geometry management. See |
| 219 | :ref:`constrainedlayout_guide` for details. |
| 220 | """ |
| 221 | |
| 222 | _adjust_compatible = False |
| 223 | _colorbar_gridspec = False |
| 224 | |
| 225 | def __init__(self, *, h_pad=None, w_pad=None, |
| 226 | hspace=None, wspace=None, rect=(0, 0, 1, 1), |
| 227 | compress=False, **kwargs): |
| 228 | """ |
| 229 | Initialize ``constrained_layout`` settings. |
| 230 | |
| 231 | Parameters |
| 232 | ---------- |
| 233 | h_pad, w_pad : float |
| 234 | Padding around the Axes elements in inches. |
| 235 | Default to :rc:`figure.constrained_layout.h_pad` and |
| 236 | :rc:`figure.constrained_layout.w_pad`. |
| 237 | hspace, wspace : float |
| 238 | Fraction of the figure to dedicate to space between the |
| 239 | axes. These are evenly spread between the gaps between the Axes. |
| 240 | A value of 0.2 for a three-column layout would have a space |
| 241 | of 0.1 of the figure width between each column. |
| 242 | If h/wspace < h/w_pad, then the pads are used instead. |
| 243 | Default to :rc:`figure.constrained_layout.hspace` and |
| 244 | :rc:`figure.constrained_layout.wspace`. |
| 245 | rect : tuple of 4 floats |
| 246 | Rectangle in figure coordinates to perform constrained layout in |
| 247 | (left, bottom, width, height), each from 0-1. |
| 248 | compress : bool |
| 249 | Whether to shift Axes so that white space in between them is |
| 250 | removed. This is useful for simple grids of fixed-aspect Axes (e.g. |
| 251 | a grid of images). See :ref:`compressed_layout`. |
| 252 | """ |
| 253 | super().__init__(**kwargs) |
| 254 | # set the defaults: |
| 255 | self.set(w_pad=mpl.rcParams['figure.constrained_layout.w_pad'], |
| 256 | h_pad=mpl.rcParams['figure.constrained_layout.h_pad'], |
| 257 | wspace=mpl.rcParams['figure.constrained_layout.wspace'], |
| 258 | hspace=mpl.rcParams['figure.constrained_layout.hspace'], |
| 259 | rect=(0, 0, 1, 1)) |
| 260 | # set anything that was passed in (None will be ignored): |
| 261 | self.set(w_pad=w_pad, h_pad=h_pad, wspace=wspace, hspace=hspace, |
| 262 | rect=rect) |
| 263 | self._compress = compress |
| 264 | |
| 265 | def execute(self, fig): |
| 266 | """ |
| 267 | Perform constrained_layout and move and resize Axes accordingly. |
| 268 | |
| 269 | Parameters |
| 270 | ---------- |
| 271 | fig : `.Figure` to perform layout on. |
| 272 | """ |
| 273 | width, height = fig.get_size_inches() |
no outgoing calls
no test coverage detected
searching dependent graphs…