在jupyter笔记本中使用熊猫,我为该Motion的分类所着色的示例Motion生成了一个交互作用得分的条形图。分类为VS,SUB,OBV,VO和CTRL。因此,我将此代码用于绘图:
colors = {'VS':'blue',
'SUB':'green',
'OBV': 'orange',
'VO': 'red',
'CTRL': 'black'}
cat_data.sort_values('Interaction_rounded').plot.bar(x='Motion',
y='Interaction_rounded',
rot=90,
title='All Motions Interaction Score Colored by Classification',
color = [colors[i] for i in cat_data['Classification']],
fontsize = 8,
legend = False)
但是我得到这张图:
你们知道应该是黑色的CTRL是不是?与“拳头轻扫”相同,它不应该是黑色的。有人知道我可以做些什么来纠正此问题吗?
这是我的工作:
colors = {'VS':'blue',
'SUB':'green',
'OBV': 'orange',
'VO': 'red',
'CTRL': 'black'}
_ = (
cat_data
.sort_values('Interaction_rounded')
.assign(colors=lambda df: df['Classification'].map(colors)
.pipe(lambda df:
df.plot.bar(
x='Motion',
y='Interaction_rounded',
rot=90,
title='All Motions Interaction Score Colored by Classification',
color=df['colors'], # now you can access the latest version of the dataframe
fontsize=8,
legend=False
)
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句