【问题标题】:Matplotlib 3D plot colors from different classes from Dataframe来自 Dataframe 的不同类的 Matplotlib 3D 绘图颜色
【发布时间】:2018-12-06 19:53:38
【问题描述】:

我正在尝试从本质上从两个不同类中提取的点云数据在 Matplotlib 中绘制 3D 图。

但是,我无法将这些类区分为不同的颜色。我的代码如下。

x=pd.DataFrame(np.array(x).reshape(-1,1))
y=pd.DataFrame( np.array(y).reshape( -1, 1 ) )
z=pd.DataFrame(np.array(z).reshape(-1,1))
target=pd.DataFrame(np.array(target).reshape(-1,1))
new_data=[x,y,z,target]

new_data = pd.concat(new_data, axis=1, ignore_index=True )

new_data.columns = ['x','y','z','target']


colors=[]

fig=plt.figure(figsize=(8,8))
ax=fig.add_subplot(111,projection='3d')
ax.scatter(new_data.x,new_data.y,new_data.z,color='target')

颜色参数无法链接到我的数据框中“目标”列中的类。有什么我遗漏的吗?

【问题讨论】:

    标签: python pandas matplotlib data-visualization


    【解决方案1】:

    我自己找到了答案 - 使用以下 col=new_data['target'].map({'Variable1':'r','Variable2 ':'g','Variable3':'b'}) 将 Dataframe 映射到 Color 的参数

    【讨论】:

      【解决方案2】:

      您是说颜色应该来自字符串“target”的值。改成c=new_data.target

      【讨论】:

      • 我猜这是一个问题,因为 dataframe-Target 中的值包含多个不直接链接到颜色参数的类。我通过使用以下映射它来解决它。 col=new_data['target'].map({'China':'r','Caucasian':'g'})
      猜你喜欢
      • 1970-01-01
      • 2015-10-02
      • 2016-09-23
      • 2013-07-19
      • 2020-07-22
      • 1970-01-01
      • 2021-03-07
      • 2022-01-20
      • 2020-08-13
      相关资源
      最近更新 更多