Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn FacetGrid Stacked Bar Chart

is it possible to create a stacked barchart facetgrid with seaborn?

g = sns.FacetGrid(data, col="city", col_order=cities, col_wrap=3, height=5)
g = g.map(plt.plot, x="date", y="value", hue='time_bin', stacked=True, marker=".")

unfortunately does not work.

like image 585
Fabian Bosler Avatar asked Sep 05 '25 03:09

Fabian Bosler


1 Answers

From what I can guess from your code, it can be done with plt:

fig, axes = plt.subplots(5,3,figsize=(12,20))
axes = axes.flatten()

for city,ax in zip(cities,axes):
    df = data[data.city==city].groupby(['date','time_bin']).value.count()
    df.unstack().plot.bar(ax=ax, stacked=True)

Output:

enter image description here

like image 157
Quang Hoang Avatar answered Sep 07 '25 17:09

Quang Hoang