Skip to content

matplotlib 3.1.2: mplot3d must be explicitly imported to work #16192

@pajot

Description

@pajot

Bug report

Bug summary

In "API Changes - Behavior changes" (https://matplotlib.org/api/api_changes.html#behavior-changes) it says

"mplot3d auto-registration

mpl_toolkits.mplot3d is always registered by default now. It is no longer necessary to import mplot3d to create 3d axes with

ax = fig.add_subplot(111, projection="3d")"

I am not seeing this behaviour.

Code for reproduction

import matplotlib.pyplot as plt
fig3 = plt.figure()
ax3 = fig3.add_subplot(111, projection='3d')

and

mpl.projections.get_projection_names()

Actual outcome

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/Berechnung/lib64/python3.6/site-packages/matplotlib/projections/__init__.py in get_projection_class(projection)
     57     try:
---> 58         return projection_registry.get_projection_class(projection)
     59     except KeyError:

~/Berechnung/lib64/python3.6/site-packages/matplotlib/projections/__init__.py in get_projection_class(self, name)
     24         """
---> 25         return self._all_projection_types[name]
     26 

KeyError: '3d'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-2-95b16d9d7a18> in <module>
      1 import matplotlib.pyplot as plt
      2 fig3 = plt.figure()
----> 3 ax3 = fig3.add_subplot(111, projection='3d')

~/Berechnung/lib64/python3.6/site-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs)
   1394         else:
   1395             projection_class, kwargs, key = \
-> 1396                 self._process_projection_requirements(*args, **kwargs)
   1397 
   1398             # try to find the axes with this key in the stack

~/Berechnung/lib64/python3.6/site-packages/matplotlib/figure.py in _process_projection_requirements(self, polar, projection, *args, **kwargs)
   1118 
   1119         if isinstance(projection, str) or projection is None:
-> 1120             projection_class = projections.get_projection_class(projection)
   1121         elif hasattr(projection, '_as_mpl_axes'):
   1122             projection_class, extra_kwargs = projection._as_mpl_axes()

~/Berechnung/lib64/python3.6/site-packages/matplotlib/projections/__init__.py in get_projection_class(projection)
     58         return projection_registry.get_projection_class(projection)
     59     except KeyError:
---> 60         raise ValueError("Unknown projection %r" % projection)
     61 
     62 

ValueError: Unknown projection '3d'

<Figure size 432x288 with 0 Axes>

and

['aitoff', 'hammer', 'lambert', 'mollweide', 'polar', 'rectilinear']

Expected outcome

An Axes3d object and the following output of mpl.projections.get_projection_names():

['3d', 'aitoff', 'hammer', 'lambert', 'mollweide', 'polar', 'rectilinear']

Matplotlib version

  • Operating system: Linux thinkpad_T500 4.19.72-gentoo Updated docs to refer to git #3 SMP Sun Dec 8 14:16:38 CET 2019 x86_64 Intel(R) Core(TM)2 Duo CPU T9400 @ 2.53GHz GenuineIntel GNU/Linux
  • Matplotlib version: 3.1.2
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.6.9
  • Jupyter version (if applicable): jupyter core : 4.6.1, jupyter-notebook : 6.0.2

Matplotlib is running in a python environment and was installed with pip.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions