Repository: matplotlib/matplotlib
Pull request: FIX: correctly unset the layout engine in Figure.tight_layout

## PR Summary

closes #7805


## PR Checklist

<!-- Please mark any checkboxes that do not apply to this PR as [N/A]. -->

**Documentation and Tests**
- [x] Has pytest style unit tests (and `pytest` passes)
- [na] Documentation is sphinx and numpydoc compliant (the docs should [build](https://matplotlib.org/devel/documenting_mpl.html#building-the-docs) without error).
- [na] New plotting related features are documented with examples.


Problem statement:
tight layout kwargs have no effect if rc autolayout setting is set (MPL 1.5.3)
### Bug report

**Bug summary**

kwargs passed to tight layout do not have an effect if rc the figure.autolayout setting is set

**Code for reproduction**

No padding is inserted in the following example if figure.autolayout is set to True in the rc

```python
import matplotlib.pyplot as plt
fig, axes = plt.subplots(ncols=2)
fig.tight_layout(w_pad=10)
```

**Matplotlib version**

Tested with a conda installed Matplotlib 1.5.3 on Ubuntu Linux.

Hints from issue discussion:
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear.  Thanks for your help!
This is still a bug.  The source of this bug is definitely different than it was before (as we have radically re-done this code).

The issue is that:
 - tight layout tries to run a one-off layout and then un-set the layout manager to make it "stick"
 - if `None` is passed to `fig.set_layout_manager` it falls back to doing what the rcparams say
 - that re-installs a new TightLayout engine with the default parameters

I think the fix is to make the "unset layout manager" more robust.
https://github.com/matplotlib/matplotlib/blob/8ca75e445d136764bbc28d8db7346c261e8c6c41/lib/matplotlib/figure.py#L2573-L2638

and 

https://github.com/matplotlib/matplotlib/blob/8ca75e445d136764bbc28d8db7346c261e8c6c41/lib/matplotlib/figure.py#L3517-L3518

are the badly interacting bits of code.

I think we need a (private) flag to say "make it None, ignore rcparams" (or use rccontext in the `finally`?).
I haven’t followed this whole thread, but if we want to not have a layout engine we can pass `set_layout_engine("none")`.
Ah, then using `'none'` is probably the right thing to do.

Commit message: FIX: correctly unset the layout engine in Figure.tight_layout

closes #7805

Patch to review:
diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py
index 926944e5a577..32c5388592d0 100644
--- a/lib/matplotlib/figure.py
+++ b/lib/matplotlib/figure.py
@@ -3515,7 +3515,7 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
                     and previous_engine is not None:
                 _api.warn_external('The figure layout has changed to tight')
         finally:
-            self.set_layout_engine(None)
+            self.set_layout_engine('none')
 
 
 def figaspect(arg):
diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py
index d8b06003cd00..64477f4e216a 100644
--- a/lib/matplotlib/tests/test_figure.py
+++ b/lib/matplotlib/tests/test_figure.py
@@ -659,6 +659,15 @@ def test_invalid_layouts():
         fig.set_layout_engine("constrained")
 
 
+@check_figures_equal(extensions=["png"])
+def test_tightlayout_autolayout_deconfilct(fig_test, fig_ref):
+    for fig, autolayout in zip([fig_ref, fig_test], [False, True]):
+        with mpl.rc_context({'figure.autolayout': autolayout}):
+            axes = fig.subplots(ncols=2)
+            fig.tight_layout(w_pad=10)
+        assert isinstance(fig.get_layout_engine(), PlaceHolderLayoutEngine)
+
+
 @pytest.mark.parametrize('layout', ['constrained', 'compressed'])
 def test_layout_change_warning(layout):
     """


Code review comments:
diff_hunk: @@ -659,6 +659,15 @@ def test_invalid_layouts():
         fig.set_layout_engine("constrained")
 
 
+@check_figures_equal(extensions=["png"])
+def test_tightlayout_autolayout_deconfilct(fig_test, fig_ref):
path: lib/matplotlib/tests/test_figure.py
text: @user1:
```suggestion
def test_tightlayout_autolayout_deconflict(fig_test, fig_ref):
```
typo I think