import numpy as np # Defining colors palette np.random.seed(42) df_plot = df[['month', 'year', 'PJME_MW']].dropna().groupby(['month', 'year']).mean()[['PJME_MW']].reset_index() years = df_plot['year'].unique() colors = np.random.choice(list(mpl.colors.XKCD_COLORS.keys()), len(years), replace=False) # Plot plt.figure(figsize=(16,12)) for i, y in enumerate(years): if i > 0: plt.plot('month', 'PJME_MW', data=df_plot[df_plot['year'] == y], color=colors[i], label=y) if y == 2018: plt.text(df_plot.loc[df_plot.year==y, :].shape[0]+0.3, df_plot.loc[df_plot.year==y, 'PJME_MW'][-1:].values[0], y, fontsize=12, color=colors[i]) else: plt.text(df_plot.loc[df_plot.year==y, :].shape[0]+0.1, df_plot.loc[df_plot.year==y, 'PJME_MW'][-1:].values[0], y, fontsize=12, color=colors[i]) # Setting labels plt.gca().set(ylabel= 'PJME_MW', xlabel = 'Month') plt.yticks(fontsize=12, alpha=.7) plt.title("Seasonal Plot - Monthly Consumption", fontsize=20) plt.ylabel('Consumption [MW]') plt.xlabel('Month') plt.show()