我有三维数组,用于X值、Y值和Z值.我想用X和Y做一个二维的情节,并有Z的颜色.
然而,每次我试着跑,我就会得到
AttributeError: 'list' object has no attribute 'shape'目前我有:
X=np.array(X)
Y=np.array(Y)
Z=np.array(Z)
fig = pyplot.figure()
ax = fig.add_subplot(111)
p = ax.scatter(X,Y,Z)我也试过
fig, ax = pyplot.figure()
p = ax.pcolor(X,Y,Z,cmap = cm.RdBu)
cb = fig.colorbar(p,ax=ax)都给了我同样的错误。
发布于 2014-04-15 20:01:19
plt.scatter的文档要求输入如下:
matplotlib.pyplot.scatter(x, y, s=20, ...)这不是(x,y,z)。您将s (点的大小)设置为Z值。若要提供颜色的"Z“值,请将其作为c参数传递:
import numpy as np
import pylab as plt
# Example points that use a color proportional to the radial distance
N = 2000
X = np.random.normal(size=N)
Y = np.random.normal(size=N)
Z = (X**2+Y**2)**(1/2.0)
plt.scatter(X,Y,c=Z,linewidths=.1)
plt.axis('equal')
plt.show()

https://stackoverflow.com/questions/23092867
复制相似问题