Skip to content

[Bug]: plt.subplots() cannot take the sharez or shareview keyword for 3D plots #25822

Open
@scottshambaugh

Description

@scottshambaugh

Bug summary

When initializing 3D plots using the plt.subplots interface, the sharez keyword is not implemented. This also applies to the shareview keyword introduced in #25821.

Would like to get some other opinions on if 3d-specific keywords should go into the Figure / subplots method.

Code for reproduction

import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'}, sharex=True)  # works
fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'}, sharey=True)  # works
fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'}, sharez=True)  # fails
fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'}, shareview=True)  # fails

Actual outcome

Exception has occurred: AttributeError
Figure.set() got an unexpected keyword argument 'sharez'
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/artist.py", line 1192, in _update_props
    raise AttributeError(
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/artist.py", line 1218, in _internal_update
    return self._update_props(
           ^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/artist.py", line 1226, in set
    return self._internal_update(cbook.normalize_kwargs(kwargs, self))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/artist.py", line 147, in <lambda>
    cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/figure.py", line 201, in __init__
    self.set(**kwargs)
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/figure.py", line 2459, in __init__
    super().__init__(**kwargs)
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/backend_bases.py", line 3387, in new_figure_manager
    fig = fig_cls(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/pyplot.py", line 429, in new_figure_manager
    return _get_backend_mod().new_figure_manager(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/pyplot.py", line 898, in figure
    manager = new_figure_manager(
              ^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/lib/matplotlib/pyplot.py", line 1562, in subplots
    fig = figure(**fig_kw)
          ^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Scott/Documents/Documents/Coding/matplotlib/test_3d_plot.py", line 18, in <module>
    fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'}, sharez=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: Figure.set() got an unexpected keyword argument 'sharez'

Expected outcome

Plot should generate and share z axes.

Matplotlib Version

latest main

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions