本文介绍了Seaborn FacetGrid 堆积条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 seaborn 创建堆叠条形图 facetgrid?

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.

推荐答案

根据我的代码猜测,可以使用 plt :

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)

输出:

这篇关于Seaborn FacetGrid 堆积条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 06:59