'How to make a stacked bar chart with specified bar heights in seaborn
I have a pandas dataframe like below. In the dataset, there are 3 segment (A,B,C). Column SEG_PCT is segment pecentage value. Each Segment has two groups. Column GRP_PCT is pecentage value for each group within each segment.
I need to plot a bar chart (using seaborn or pandas plot), with 3 stacked bars (A, B, C), with bar height as value of column SEG_PCT. Within each stacked bar are the GRP with GRP_PCT value.
I'm new to seaborn and pandas plot. Have no idea how to make this kind of plot. Thanks a lot in advance.
df = pd.DataFrame({'SEG': ['A', 'A', 'B', 'B', 'C', 'C'],
'SEG_PCT': [0.6, 0.6, 0.4, 0.4, 0.2, 0.2],
'GRP':['GRP1', 'GRP2','GRP1','GRP2','GRP1','GRP2',],
'GRP_PCT': [0.7, 0.3, 0.6, 0.4, 0.1, 0.9]
})
SEG SEG_PCT GRP GRP_PCT
0 A 0.6 GRP1 0.7
1 A 0.6 GRP2 0.3
2 B 0.4 GRP1 0.6
3 B 0.4 GRP2 0.4
4 C 0.2 GRP1 0.1
5 C 0.2 GRP2 0.9
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
