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.