Skip to content

[Bug]: subplots doesn't accept width_ratios parameter #23928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StefRe opened this issue Sep 18, 2022 · 2 comments
Closed

[Bug]: subplots doesn't accept width_ratios parameter #23928

StefRe opened this issue Sep 18, 2022 · 2 comments

Comments

@StefRe
Copy link
Contributor

StefRe commented Sep 18, 2022

Bug summary

Contrary to the documentation, subplots doesn't accept width_ratios or height_ratios as direct parameters.

Code for reproduction

import matplotlib.pyplot as plt

fig, axs = plt.subplots(ncols=2, width_ratios=[1, 3])

Actual outcome

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

[<ipython-input-5-3134bfb5f7d5>](https://localhost:8080/#) in <module>
      1 import matplotlib.pyplot as plt
      2 
----> 3 fig, axs = plt.subplots(ncols=2, width_ratios=[1, 3])
      4 
      5                         #gridspec_kw=dict(width_ratios=[1, 3]))

8 frames

[/usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py](https://localhost:8080/#) in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
   1451 
   1452     """
-> 1453     fig = figure(**fig_kw)
   1454     axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
   1455                        squeeze=squeeze, subplot_kw=subplot_kw,

[/usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py](https://localhost:8080/#) in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
    807             num, figsize=figsize, dpi=dpi,
    808             facecolor=facecolor, edgecolor=edgecolor, frameon=frameon,
--> 809             FigureClass=FigureClass, **kwargs)
    810         fig = manager.canvas.figure
    811         if fig_label:

[/usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py](https://localhost:8080/#) in new_figure_manager(*args, **kwargs)
    323     """Create a new figure manager instance."""
    324     _warn_if_gui_out_of_main_thread()
--> 325     return _get_backend_mod().new_figure_manager(*args, **kwargs)
    326 
    327 

[/usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py](https://localhost:8080/#) in new_figure_manager(cls, num, *args, **kwargs)
   3491         from matplotlib.figure import Figure
   3492         fig_cls = kwargs.pop('FigureClass', Figure)
-> 3493         fig = fig_cls(*args, **kwargs)
   3494         return cls.new_figure_manager_given_figure(num, fig)
   3495 

[/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py](https://localhost:8080/#) in __init__(self, figsize, dpi, facecolor, edgecolor, linewidth, frameon, subplotpars, tight_layout, constrained_layout, layout, **kwargs)
   2298             %(Figure:kwdoc)s
   2299         """
-> 2300         super().__init__(**kwargs)
   2301 
   2302         if layout is not None:

[/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py](https://localhost:8080/#) in __init__(self, **kwargs)
    214         self.stale = True
    215         self.suppressComposite = None
--> 216         self.set(**kwargs)
    217 
    218     def _get_draw_artists(self, renderer):

[/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py](https://localhost:8080/#) in <lambda>(self, **kwargs)
    115             return
    116 
--> 117         cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)
    118         cls.set.__name__ = "set"
    119         cls.set.__qualname__ = f"{cls.__qualname__}.set"

[/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py](https://localhost:8080/#) in set(self, **kwargs)
   1165         # module.
   1166         kwargs = cbook.normalize_kwargs(kwargs, self)
-> 1167         return self.update(kwargs)
   1168 
   1169     @contextlib.contextmanager

[/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py](https://localhost:8080/#) in update(self, props)
   1065                     func = getattr(self, f"set_{k}", None)
   1066                     if not callable(func):
-> 1067                         raise AttributeError(f"{type(self).__name__!r} object "
   1068                                              f"has no property {k!r}")
   1069                     ret.append(func(v))

AttributeError: 'Figure' object has no property 'width_ratios'

Expected outcome

according to the docs, it should be the same as for

python fig, axs = plt.subplots(ncols=2, gridspec_kw=dict(width_ratios=[1, 3]))

Additional information

No response

Operating system

Linux

Matplotlib Version

3.5.3

Matplotlib Backend

module://ipykernel.pylab.backend_inline

Python version

3.7.14

Jupyter version

5.3.1

Installation

pip

@timhoffm
Copy link
Member

This feature has only been added in 3.6.0. It is not in the 3.5.3 docs https://matplotlib.org/3.5.3/api/_as_gen/matplotlib.pyplot.subplots.html.

You might have confused the versions because of #23920.

@StefRe
Copy link
Contributor Author

StefRe commented Sep 18, 2022

Yes, you're right - I came from the devdocs and switched to stable:

image

@StefRe StefRe closed this as completed Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants