Skip to content

[Bug]: constrained_layout_pads as kwargs of Figure #22029

Open
@StefRe

Description

@StefRe

Bug summary

According to the figure documentation (other parameters) it should be possible pass figure kwargs in plt.subplots():

fig, ax = plt.subplots(layout='constrained',
                       constrained_layout_pads={'w_pad': 0.5, 'h_pad': 0.5})

which results, however, in a

TypeError: set_constrained_layout_pads() takes 1 positional argument but 2 were given

The documentation mentions a single value (float), although the parameter name is in plural (and set_constrained_layout_pads takes up to four parameters):

constrained_layout_pads float, default: rcParams["figure.constrained_layout.w_pad"] (default: 0.04167)

but plt.subplots(constrained_layout_pads=0.5) results in the same error.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots(layout='constrained',
                       constrained_layout_pads={'w_pad': 0.5, 'h_pad': 0.5})

Actual outcome


  File "/usr/lib/python3.10/site-packages/matplotlib/pyplot.py", line 1434, in subplots
    fig = figure(**fig_kw)

  File "/usr/lib/python3.10/site-packages/matplotlib/pyplot.py", line 787, in figure
    manager = new_figure_manager(

  File "/usr/lib/python3.10/site-packages/matplotlib/pyplot.py", line 306, in new_figure_manager
    return _backend_mod.new_figure_manager(*args, **kwargs)

  File "/usr/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 3493, in new_figure_manager
    fig = fig_cls(*args, **kwargs)

  File "/usr/lib/python3.10/site-packages/matplotlib/figure.py", line 2238, in __init__
    super().__init__(**kwargs)

  File "/usr/lib/python3.10/site-packages/matplotlib/figure.py", line 216, in __init__
    self.set(**kwargs)

  File "/usr/lib/python3.10/site-packages/matplotlib/artist.py", line 116, in <lambda>
    cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)

  File "/usr/lib/python3.10/site-packages/matplotlib/artist.py", line 1164, in set
    return self.update(kwargs)

  File "/usr/lib/python3.10/site-packages/matplotlib/artist.py", line 1066, in update
    ret.append(func(v))

TypeError: Figure.set_constrained_layout_pads() takes 1 positional argument but 2 were given

Expected outcome

no error

Additional information

also discussed at discours

Operating system

Arch

Matplotlib Version

3.5.1

Matplotlib Backend

Qt5Agg

Python version

3.10.1

Jupyter version

No response

Installation

Linux package manager

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions