我试图用stripplot绘制数据集。这是标题(共有25列):
Labels Acidobacteria Actinobacteria Armatimonadetes Bacteroidetes
0 0 0 495 NaN 27859
1 1 0 1256 NaN 46582
2 0 0 1081 NaN 23798
3 1 0 2523 NaN 35088
4 0 0 1383 NaN 19338
我将此数据集存储在pandas数据框中,并可以使用以下方式绘制:
^{pr2}$产生this plot。在
我想设置色调以反映'Labels'
列。当我尝试:
sns.stripplot(x=df.columns.values.tolist(),y=df,data=df,hue='Labels')
我得到:
ValueError: cannot copy sequence with size 26 to array axis with dimension 830
所以我想出来了。我不得不通过叠加和重新索引来重新排列数据:
哪些输出:
^{pr2}$接下来,我必须创建一个新列,为每个数据点分配标签:
所以现在:
然后画出:
产生this graph。在
谢谢你的帮助!在
我想扩展一下你的答案(实际上我会压缩它),因为这可以在“一行代码”中完成:
避免重新创建
"Labels"
列的技巧是在堆栈之前将其设置为index。在输出:
^{pr2}$相关问题 更多 >
编程相关推荐