如何使用matplotlib做3D图?

时间:2019-11-02 21:00:21

标签: matplotlib

我尝试使用matplotlib绘制3d图形,如下所示:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig = plt.figure()
ax = Axes3D(fig)
Axes3D.scatter([1,2,3], [3,4,1], [4,5,3],marker='o')

我收到以下错误,这似乎是库错误:

/opt/conda/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axes3d.py in scatter(self, xs, ys, zs, zdir, s, c, depthshade, *args, **kwargs)
   2295         """
   2296 
-> 2297         had_data = self.has_data()
   2298 
   2299         xs, ys, zs = np.broadcast_arrays(

AttributeError: 'list' object has no attribute 'has_data'

所以我尝试了:

fig = plt.figure()
ax = Axes3D(fig)
Axes3D.scatter(np.array([1,2,3]), np.array([3,4,1]), np.array([4,5,3]),marker='o')

但是我得到这个错误:

/opt/conda/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axes3d.py in scatter(self, xs, ys, zs, zdir, s, c, depthshade, *args, **kwargs)
   2295         """
   2296 
-> 2297         had_data = self.has_data()
   2298 
   2299         xs, ys, zs = np.broadcast_arrays(

AttributeError: 'numpy.ndarray' object has no attribute 'has_data'

0 个答案:

没有答案