我想基于hue参数堆叠水平条。我想按比例(即100%)堆叠它们。
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame('file.csv')
sns.barplot(x="count", y="new_placement_name", data=df, hue = "index_range" , color="b",ci = None)
placementname index_range Count
0 Great|5/1/2020|||... High 7
1 Great|5/1/2020|||... Low 4
2 Great|5/1/2020|||... Medium 39
3 Great|5/1/2020|||... Poor 40
4 Great|5/1/2020|||... Very High 23
答案 0 :(得分:1)
Seaborn不支持堆积的条形图:https://randyzwitch.com/creating-stacked-bar-chart-seaborn/
您可以用熊猫来做
:df['pct'] = df['Count'] / sum(df['Count'])
df.pivot(index='new_placement_name',columns='Count',
values='pct').plot(kind='barh',stacked=True,colormap='Blues',rot=90)
结果:
答案 1 :(得分:-1)
是的,您可以通过seaborn做到。这里是文档的链接: barh in seaborn