0

我正在尝试用子图渲染一个图。每个子图都被垂直挤压,我不明白为什么。我试过设置纵横比,但这似乎使它变窄,没有解决图像不够高而无法使用的问题。我正在使用tight_layout,但输出大小足以让它更大。我知道我可以使用网格布局更具体地设置图像的大小,但我觉得我缺少一些更简单的东西,因为这对于我的任何类似的子图都不是问题。

谢谢!

我的绘图输出

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')
4

0 回答 0