如何在 seaborn 中获得 2 个独立的地块?

How to obtain 2 separate plots in seaborn?

我有一个大函数,它输出一个数据框和 2 个图表。像这样:

summary = pd.concat([mean, std], axis=1)
chart1 = sns.tsplot(sample['x'].cumsum())
chart2 = sns.tsplot(summary['mean'])
result = [summary, chart1, chart2]
return result

一切正常,除了,我只得到一张包含两个时间序列的图表。我想得到两个单独的图表。我该怎么做?

谢谢

将显式 matplotlib 对象提供给 tsplot:

import matplotlib.pyplot as plt
import seaborn as sns

def whatever(mean, std, *args, **kwargs):
    summary = pd.concat([mean, std], axis=1)
    chart1, ax1 = plt.subplots()
    sns.tsplot(sample['x'].cumsum(), ax=ax1)

    chart2, ax2 = plt.subplots()
    sns.tsplot(summary['mean'], ax=ax2)
    result = [summary, chart1, chart2]
    return result