【问题标题】:How to obtain 2 separate plots in seaborn?如何在seaborn中获得2个独立的地块?
【发布时间】:2015-06-02 21:56:50
【问题描述】:

我有一个很大的函数,它的输出是一个数据框和 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

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

谢谢

【问题讨论】:

    标签: python python-2.7 pandas seaborn


    【解决方案1】:

    将显式 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2014-10-17
      相关资源
      最近更新 更多