当数据框中有两个类别时,如何并排创建 2 个图?

How to create 2 plots side by side when there are two categories in your dataframe?

我有一个类似这样的数据集:

d = {'label': ['true', 'false', 'true', 'false', 'false'],
     'count': [4, 24, 31, 2, 3],
     'date': [2019-01-01, 2019-01-02, 2019-01-03, 2019-01-04, 2019-01-05]}
df = pd.DataFrame(d)

我正在尝试使用 count 为每个 label 创建一个累积和并将它们并排绘制。 但是,我只能通过以下方式做到这一点:

pivot = pd.pivot_table(df, values="count", index=["date"], columns=["label"], aggfunc=np.sum)
pivot = pivot.cumsum()

plt.rcParams["figure.figsize"] = [20,7]
plt.plot(pivot)
plt.ylabel('Cumulative number')
plt.xlabel('Time')

它工作正常,除了两个类别都在一个图中。我想将它们与 y-label 并排创建为 10^0、10^1、10^2 等等,如下所示:

有什么指导吗?

您可以使用 seaborn:

import seaborn as sns

sns.relplot(data=pivot.melt(ignore_index=False), x='date', y='value', col='label', kind='scatter')