|
53 | 53 | from matplotlib.gridspec import GridSpec |
54 | 54 | from matplotlib.layout_engine import ( |
55 | 55 | ConstrainedLayoutEngine, TightLayoutEngine, LayoutEngine, |
56 | | - PlaceHolderLayoutEngine |
| 56 | + PlaceHolderLayoutEngine, TLPlaceHolderLayoutEngine |
57 | 57 | ) |
58 | 58 | import matplotlib.legend as mlegend |
59 | 59 | from matplotlib.patches import Rectangle |
@@ -3522,17 +3522,25 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): |
3522 | 3522 | # note that here we do not permanently set the figures engine to |
3523 | 3523 | # tight_layout but rather just perform the layout in place and remove |
3524 | 3524 | # any previous engines. |
3525 | | - engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad, |
3526 | | - rect=rect) |
| 3525 | + engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) |
3527 | 3526 | try: |
3528 | 3527 | previous_engine = self.get_layout_engine() |
3529 | 3528 | self.set_layout_engine(engine) |
3530 | 3529 | engine.execute(self) |
3531 | | - if not isinstance(previous_engine, TightLayoutEngine) \ |
3532 | | - and previous_engine is not None: |
3533 | | - _api.warn_external('The figure layout has changed to tight') |
| 3530 | + if previous_engine is not None and not isinstance( |
| 3531 | + previous_engine, (TightLayoutEngine, TLPlaceHolderLayoutEngine) |
| 3532 | + ): |
| 3533 | + _api.warn_external("The figure layout has changed to tight") |
3534 | 3534 | finally: |
3535 | | - self.set_layout_engine('none') |
| 3535 | + if previous_engine is not None: |
| 3536 | + self.set_layout_engine( |
| 3537 | + TLPlaceHolderLayoutEngine( |
| 3538 | + previous_engine.adjust_compatible, |
| 3539 | + previous_engine.colorbar_gridspec |
| 3540 | + ) |
| 3541 | + ) |
| 3542 | + else: |
| 3543 | + self.set_layout_engine(TLPlaceHolderLayoutEngine(True, True)) |
3536 | 3544 |
|
3537 | 3545 |
|
3538 | 3546 | def figaspect(arg): |
|
0 commit comments