3D散点图matplotlib,为绘图添加颜色不起作用



我正在创建一个3D散点图,该散点图是通过使用PCA(3个组件(转换数据而产生的。我希望我的数据根据变量"phi"进行颜色编码,phi是一个浮动数组,范围从0-360度不等。变量x:[44520,3],phi[44520,1(

我得到以下错误:

ValueError: 'c' argument has 44520 elements, which is not acceptable for use with 'x' with size 44520, 'y' with size 44520.

有线索吗?


signalt = dfonf.T # transpose the data as the cell #s are the features and the sampled data is the sample
pca = PCA(n_components=3)
x = pca.fit_transform(signalt)
fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection="3d")
pcaplot = ax.scatter3D(x[:,0],x[:,1],x[:,2],c=phi,s=0.2)
cbar = fig.colorbar(pcaplot)

变量c不能是二维的,使用转换为1D

np.squeeze(phi)

这修复了

最新更新