Fabian Bosler
Fabian Bosler

Reputation: 2510

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.

Upvotes: 4

Views: 2153

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150725

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

Upvotes: 3

Related Questions