Matplotlib Subfigures too Short

297 views Asked by At

I'm trying to render a figure with subfigures. Each subfigure is getting squashed vertically and I don't understand why. I've tried setting the aspect ratio but that just seems to make it narrower, without solving the problem that the image isn't tall enough to be useful. I'm using tight_layout but the output size is more than enough for it to be bigger. I know I can set the size of my images more specifically with grid layouts, but I feel like there's something simpler that I'm missing, since this hasn't been an issue with any of my similar plots with subfigures.

Thanks!

My Plot Output

def plot_at_all_intervals_mod(series, series_name, series_file_name, is_date, write, ROLL_NUM = 4):
    plt.close()
    fig, axs = plt.subplots(4, 2)
    
#     for row in axs:
#         for ax in row:
#             ax.set_aspect('equal')
    
    #absolute
    if is_date:
        my_range = (unix_time_to_year(min(series)), unix_time_to_year(max(series)))
        values, bins, _ = axs[0,0].hist(unix_time_to_year(series), log=False, bins=200, range=my_range)
    else:
        my_range = (min(series) / SECONDS_IN_A_YEAR, max(series) / SECONDS_IN_A_YEAR) 
        values, bins, _ = axs[0,0].hist(series / SECONDS_IN_A_YEAR, log=False, bins=200, range=my_range)
    bins = bins.tolist()[:-1]
    values = circular_moving_average(values.tolist(), ROLL_NUM)
    axs[0,0].plot(bins,values)
    axs[0,0].set_xlabel('Absolute Time')
    axs[0,0].set_ylabel('Number of Logs')
    axs[0,0].set_title(f'Distribution of {series_name} \nOver Time')
    
    #year
    values, bins, _ = axs[0,1].hist(unix_time_to_day_of_year(series), log=False, bins=365*24)
    bins = bins.tolist()[:-1 ]
    values = circular_moving_average(values.tolist(), ROLL_NUM)
    axs[0,1].plot(bins,values)
    axs[0,1].set_xlabel('Day of Year (Starting Jan 1st)')
    axs[0,1].set_ylabel('Number of Logs')
    axs[0,1].set_title(f'Distribution of {series_name} \nModulo Year')
    
    #week
    values, bins, _ = axs[1,0].hist(unix_time_to_day_of_week(series), log=False, bins=7*24*60)
    bins = bins.tolist()[:-1]
    values = circular_moving_average(values.tolist(), ROLL_NUM)
    axs[1,0].plot(bins,values)
    axs[1,0].set_xlabel('Day of Week (Starting at 0=Monday)')
    axs[1,0].set_ylabel('Number of Logs')
    axs[1,0].set_title(f'Distribution of {series_name} \nOver Time Modulo Week')
    
    #day
    values, bins, _ = axs[1,1].hist(unix_time_to_time_of_day(series), log=False, bins=24*60)
    bins = bins.tolist()[:-1 * ROLL_NUM]
    values = moving_average(values.tolist(), ROLL_NUM)
    axs[1,1].plot(bins,values)
    axs[1,1].set_xlabel('Hour of Day')
    axs[1,1].set_ylabel('Number of Logs')
    axs[1,1].set_title(f'Distribution of {series_name} \nOver Time Modulo Day')
    
    #hour
    values, bins, _ = axs[2,0].hist(unix_time_to_minute_in_hour(series), log=False, bins=60*60)
    bins = bins.tolist()[:-1]
    values = circular_moving_average(values.tolist(), ROLL_NUM)
    axs[2,0].plot(bins,values)
    axs[2,0].set_xlabel('Minute of Hour')
    axs[2,0].set_ylabel('Number of Logs')
    axs[2,0].set_title(f'Distribution of {series_name} \nOver Time Modulo Hour')
    
    #10 minutes
    values, bins, _ = axs[2,1].hist(unix_time_to_minute_in_hour(series), log=False, bins=60*60)
    bins = bins.tolist()[:-1]
    values = circular_moving_average(values.tolist(), ROLL_NUM)
    axs[2,1].plot(bins,values)
    axs[2,1].set_xlabel('Minute of Hour')
    axs[2,1].set_ylabel('Number of Logs')
    axs[2,1].set_title(f'Distribution of {series_name} \nOver Time Modulo Hour')
    
    #minute
    ROLL_NUM = 1
    values, bins, _ = axs[3,0].hist(unix_time_to_second_in_minute(series), log=False, bins=60)
    bins = bins.tolist()[:-1 * ROLL_NUM]
    values = moving_average(values.tolist(), ROLL_NUM)
    axs[3,0].plot(bins,values)
    axs[3,0].set_xlabel('Second of Minute')
    axs[3,0].set_ylabel('Number of Logs')
    axs[3,0].set_title(f'Distribution of {series_name} \n Over Time Modulo Minute')
    
    fig.suptitle(f'Distribution of {series_name} Over Different Periods', fontsize=16)
    fig.tight_layout()
    fig.set_size_inches(20, 20)
    fig.show()
    if write:
        fig.savefig(f'all-times-{series_file_name}.png')
0

There are 0 answers