Python Forum

Full Version: Sort by month in a plot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using the following code to plot a graph.

import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import folium
from folium import plugins

crime_data = pd.read_csv('~/Desktop/Assignments/Python/crime_data_sw_police_2021.csv')
crime_data = crime_data.iloc[:,[1,4,5,9,10]]
crime_data = crime_data.dropna() # Removing rows with null values

count = dict(crime_data["Month"].value_counts())
x = list (count.keys())
y = list (count.values())
plt.figure(figsize = (8,6))
plt.title(label = "Crime Rate by Month")
plt.ylabel("Number of Crimes")
plt.xlabel("Month")
plt.plot(x,y)
plt.show()
However, I get the plot like below and I want to sort it so that the Months are listed as Jan, Feb, March etc. Plot: https://prnt.sc/L8ql76ruULz-

How can I do that? Thanks in advance.