错误如下
KeyError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\projections\__init__.py in get_projection_class(projection)
57 try:
---> 58 return projection_registry.get_projection_class(projection)
59 except KeyError:
C:\ProgramData\Anaconda3\lib\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-1-102b5d3e8d3a> in <module>
5
6 fig = plt.figure()
----> 7 ax = fig.gca(projection='3d')
8
9 # Make data.
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py in gca(self, **kwargs)
1930
1931 # no axes found, so create one which spans the figure
-> 1932 return self.add_subplot(1, 1, 1, **kwargs)
1933
1934 def sca(self, a):
C:\ProgramData\Anaconda3\lib\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
C:\ProgramData\Anaconda3\lib\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()
C:\ProgramData\Anaconda3\lib\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'
解决办法:
from mpl_toolkits.mplot3d import Axes3D