pythonmatplotlibdeprecation-warning

How do you replace set_tight_layout with set_layout_engine?


When I call fig.set_tight_layout(True) on a Matplotlib figure, I receive this deprecation warning:

The set_tight_layout function will be deprecated in a future version. Use set_layout_engine instead.

How do I call set_layout_engine so as to match the current behavior as closely as possible?

Environment: 

OS: Mac
Python: 3.10.6
matplotlib: 3.7.2

Solution

  • From: https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.set_layout_engine

    fig.set_layout_engine("tight")