8000 Should constrained_layout work as plt.figure() argument? · Issue #15821 · matplotlib/matplotlib · GitHub
Skip to content
Should constrained_layout work as plt.figure() argument? #15821
Closed
@ImportanceOfBeingErnest

Description

@ImportanceOfBeingErnest

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

image

Expected outcome

image

Matplotlib version

  • Operating system: Windows 8.1
  • Matplotlib version: 3.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0