子图边界外的箱线图

时间:2020-02-02 18:40:50

标签: python matplotlib seaborn boxplot

我正在编写代码以显示两个堆叠的子图,代码如下:

    df['date'] = pd.to_datetime(df['date'])
    df['month_year'] = pd.to_datetime(df['date']).dt.to_period('M')
    df['year'] = pd.to_datetime(df['date']).dt.year

    # we don't need 2017 because our data is 2014-->2016
    df = df[df['year'] != 2017]
    fig, axarr = plt.subplots(2, 1)
    sns.boxplot(x='year', y='demand', data=df, ax=axarr[0])
    sns.boxplot(x='year', y='civilians_rank', data=df, ax=axarr[1])
    # df.boxplot(by='month_year', column='demand', ax=axarr[0])
    # df.boxplot(by='month_year', column='civilians_rank', ax=axarr[1])
    axarr[0].tick_params(axis='x', rotation=45)
    axarr[1].tick_params(axis='x', rotation=45)

    fig = plt.gcf()
    # fig.set_size_inches(18, 14)
    fig.tight_layout()
    plt.xticks(rotation=45)

但是,箱形图的高度大于子图的大小,显示如下: enter image description here

如您所见,第二个子图裁剪了一些箱形图。我尝试使用fig.set_size_inches(18, 14)the following link中的建议来增加图形大小,但没有任何改变。

0 个答案:

没有答案