0
num_rows = 7
num_cols = 2
year_index = 0
fig, axes = plt.subplots(num_rows, num_cols, figsize=(18,18))
years = df['Year'].unique()
for i in range(num_rows):
for j in range(num_cols):
    df1 = df[df['Year'] == years[year_index]]
    rolling_mean = df['PJMW_MW'].rolling(window=7*24).mean()
    axes[i][j].plot(df1['DayOfYearFloat'], rolling_mean.values)
    axes[i][j].set_title(str(years[year_index]))
    axes[i][j].set_ylim(1100, 2500)
    axes[i][j].set_xlim(0,370)
    year_index += 1
    
fig.text(0.5, 0.08, 'Elapsed Days', ha='center')
fig.text(0.08, 0.5, 'Energy Consumption (MW)', va='center', rotation='vertical')
fig.subplots_adjust(hspace=0.5)
plt.show()

I'm getting error each and every time because it says index error. I have checked about and moreover I was trying to figure out why the graphs is not getting plotted.

Sonu Kumar
  • 11
  • 4
  • Add the full Traceback error... also: [Index Error](https://stackoverflow.com/questions/1098643/does-indexerror-list-index-out-of-range-when-trying-to-access-the-nth-item-m) index `0` is out of bounds for axis `0` with size `0` heavily implies that you are working with an empty list at that line of your code. – Michael S. Sep 19 '22 at 12:06

0 Answers0