I have the following code to make a 3D scatterplot in matplotlib
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()
I have
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]
and make the call
plot_scores_3d(x, y, z, 'Test')
but get the following stack trace
/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
All the input arrays are the same size, so that's not the issue. I tried plotting again with z being an array of integers, but got the same error. Help would be much appreciated!
Turns out the issue had to do with the Python kernel in Canopy. Restarting the kernel got rid of the error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.