Python ';TypeError:此类型未实现';尝试在matplotlib中创建三维散点图时

Python ';TypeError:此类型未实现';尝试在matplotlib中创建三维散点图时,python,numpy,matplotlib,Python,Numpy,Matplotlib,我有以下代码来在matplotlib中制作3D散点图 import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt def plot_scores_3d(lambdas, Ts, scores, title): """ Plot scores (accuracy) as a function of lambda and no. iterations

我有以下代码来在matplotlib中制作3D散点图

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

def plot_scores_3d(lambdas, Ts, scores, title):
    """
      Plot scores (accuracy) as a function of lambda and no. iterations
    """
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    ax.scatter(lambdas, Ts, scores, c='r', marker='o')

    ax.set_xlabel('X Label')
    ax.set_ylabel('Y Label')
    ax.set_zlabel('Z Label')

    plt.show()
我有

x = [1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 50, 50, 50, 50, 50, 100, 100, 100, 100, 100]
y = [1, 5, 10, 15, 20, 1, 5, 10, 15, 20, 1, 5, 10, 15, 20, 1, 5, 10, 15, 20, 1, 5, 10, 15, 20]
z = [74.44444444444444, 73.33333333333333, 93.88888888888889, 94.22222222222223, 93.94444444444444, 74.44444444444444, 73.33333333333333, 93.88888888888889, 94.22222222222223, 93.94444444444444, 74.44444444444444, 73.33333333333333, 93.88888888888889, 94.22222222222223, 93.94444444444444, 74.44444444444444, 73.33333333333333, 93.88888888888889, 94.22222222222223, 93.94444444444444, 74.44444444444444, 73.33333333333333, 93.88888888888889, 94.22222222222223, 93.94444444444444]
然后打电话

plot_scores_3d(x, y, z, 'Test')
但是得到下面的堆栈跟踪

/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in scatter(self, xs, ys, zs, zdir, s, c, depthshade, *args, **kwargs)
2238         xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2239 
-> 2240         patches = Axes.scatter(self, xs, ys, s=s, c=c, *args,     **kwargs)
2241         if not cbook.iterable(zs):
2242             is_2d = True

/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, **kwargs)
3644                 linewidths=linewidths,
3645                 offsets=offsets,
-> 3646                 transOffset=kwargs.pop('transform', self.transData),
3647                 )
3648         collection.set_transform(mtransforms.IdentityTransform())

/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/collections.pyc in __init__(self, paths, sizes, **kwargs)
767         Collection.__init__(self, **kwargs)
768         self.set_paths(paths)
--> 769         self.set_sizes(sizes)
770 
771     def set_paths(self, paths):

/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/collections.pyc in set_sizes(self, sizes, dpi)
741             self._sizes = np.asarray(sizes)
742             self._transforms = np.zeros((len(self._sizes), 3, 3))
--> 743             scale = np.sqrt(self._sizes) * dpi / 72.0
744             self._transforms[:, 0, 0] = scale
745             self._transforms[:, 1, 1] = scale

TypeError: Not implemented for this type 

所有的输入数组大小都相同,所以这不是问题所在。我再次尝试用z作为整数数组进行绘图,但得到了相同的错误。非常感谢您的帮助

事实证明,这个问题与Canopy中的Python内核有关。重新启动内核消除了错误。

您的代码对我来说非常适合。我正在运行Python 2.7.6、matplotlib v1.3.1(Qt4Agg后端)、numpy 1.8.2、Ubuntu 14.04。