ValueError: Unknown projection '3d'

I'm using matplotlib and want to plot 3D points, but I get an error like this

ValueError                                Traceback (most recent call last)
<ipython-input-8-13a022ef9a21> in <module>()
      1 fig = plt.figure()
----> 2 ax = fig.add_subplot(111, projection='3d')

~/.local/lib/python3.5/site-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs)
   1347         else:
   1348             projection_class, kwargs, key = process_projection_requirements(
-> 1349                 self, *args, **kwargs)
   1350 
   1351             # try to find the axes with this key in the stack

~/.local/lib/python3.5/site-packages/matplotlib/projections/__init__.py in process_projection_requirements(figure, polar, projection, *args, **kwargs)
     79 
     80     if isinstance(projection, str) or projection is None:
---> 81         projection_class = get_projection_class(projection)
     82     elif hasattr(projection, '_as_mpl_axes'):
     83         projection_class, extra_kwargs = projection._as_mpl_axes()

~/.local/lib/python3.5/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'

What's wrong with this?

matplotlib3d-plot
2 votesJW234.00
1 Answers
JO220.00
2

You need to import another package before that script

from mpl_toolkits.mplot3d import Axes3D

It worked for me.

Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?