【问题标题】:3D scatterplot matplotlib, adding color to plot not working?3D散点图matplotlib,为绘图添加颜色不起作用?
【发布时间】:2021-03-07 15:34:28
【问题描述】:

我正在创建一个 3D 散点图,该散点图是通过使用 PCA(3 个组件)转换我的数据而产生的。我希望我的数据针对变量 '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)

【问题讨论】:

标签: python matplotlib scatter-plot scatter3d


【解决方案1】:

变量c不能是二维的,转换成一维使用

np.squeeze(phi)

这解决了它

【讨论】:

    猜你喜欢
    • 2019-05-14
    • 2011-07-26
    • 2016-12-30
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    相关资源
    最近更新 更多