0

I am writing a code to display two stacked subplots, the code is as follows:

    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)

however, the box plots heights are greater than the subplot size, displayed as follows: enter image description here

As you can see the second subplot has some boxplots cropped. I tried increasing the figure size using fig.set_size_inches(18, 14) as well as the suggestion in the following link but nothing changed.

Perl Del Rey
  • 959
  • 1
  • 11
  • 25

0 Answers0