Seaborn 可视化组 [英] Seaborn visualize groups
本文介绍了Seaborn 可视化组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 seaborn 绘制此数据框以显示每个模型的 KPI?
How can I plot this data frame using seaborn to show the KPI per model?
allFrame = pd.DataFrame({'modelName':['first','second', 'third'],
'kpi_1':[1,2,3],
'kpi_2':[2,4,3]})
不像sns.barplot(x="kpi2", y="kpi1", Hue="modelName", data=allFrame)
而是像这样每个 KPI
Not like sns.barplot(x="kpi2", y="kpi1", hue="modelName", data=allFrame)
But rather like this per KPI
推荐答案
先尝试melt
ing dataframe,然后你就可以使用seaborn
进行绘图:
Try melt
ing the dataframe first, and then you can plot using seaborn
:
import pandas as pd
import seaborn as sns
allFrame = pd.DataFrame({'modelName':['first','second', 'third'],
'kpi_1':[1,2,3],
'kpi_2':[2,4,3]})
allFrame2 = pd.melt(frame=allFrame,
id_vars=['modelName'],
value_vars=["kpi_1","kpi_2"],
value_name="Values", var_name="kpis")
sns.barplot(x="kpis", y="Values", hue="modelName", data=allFrame2)
谢谢!
这篇关于Seaborn 可视化组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文