Bug report
Bug summary
Might be a documentation issue. The constrainedlayout_guide says
constrained_layout needs to be activated before any axes are added to a figure. Two ways of doing so are
- using the respective argument to
subplots() or figure(),
- [...]
However, fig = plt.figure(constrained_layout=True) does not seem to have any effect.
Code for reproduction
import matplotlib.pyplot as plt
def example_plot(ax, fontsize=12):
ax.plot([1, 2])
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_ylabel('y-label', fontsize=fontsize)
ax.set_title('Title', fontsize=fontsize)
fig = plt.figure(constrained_layout=True)
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
for ax in [ax1, ax2]:
example_plot(ax, fontsize=24)
plt.show()
Actual outcome

Expected outcome

Matplotlib version
- Operating system: Windows 8.1
- Matplotlib version: 3.1.0
- Matplotlib backend (
print(matplotlib.get_backend())): Qt5Agg
- Python version: 3.7
Bug report
Bug summary
Might be a documentation issue. The constrainedlayout_guide says
However,
fig = plt.figure(constrained_layout=True)does not seem to have any effect.Code for reproduction
Actual outcome
Expected outcome
Matplotlib version
print(matplotlib.get_backend())): Qt5Agg