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
  • 769
  • 9
  • 19
  • 3
    I don't think there is anything cropped here. There might just not be any whiskery present in your plot, which would make sense if `1` is the lowest possible rank and `4` is the highest possible rank. – ImportanceOfBeingErnest Feb 02 '20 at 19:04
  • @ImportanceOfBeingErnest Wow I missed that out, thank you so much. – Perl Feb 03 '20 at 17:46

0 Answers0