I have the following data that I am trying to plot.
month year total_sales
May 2020 7
June 2020 2
July 2020 1
August 2020 2
September 2020 22
October 2020 11
November 2020 6
December 2020 3
January 2019 3
feburary 2019 11
March 2019 65
April 2019 22
May 2019 33
June 2019 88
July 2019 44
August 2019 12
September 2019 32
October 2019 54
November 2019 76
December 2019 23
January 2018 12
feburary 2018 32
March 2018 234
April 2018 2432
May 2018 432
Here is the code I am using to do it:
def plot_timeline_data(df):
fig, ax = plt.subplots()
ax.set_xticklabels(df['month'].unique(), rotation=90)
for name, group in df.groupby('year'):
ax.plot(group['month'], group['total_sales'], label=name,linestyle='--', marker='o')
ax.legend()
plt.tight_layout()
plt.show()
I want the order of x labels to start from january to December but my graph is starting with May to December and then resume from Jan to April as shown in the figure ( exact values of the graph are different as I changed the values). How can I put this in correct order?