Sort by month in a plot - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Sort by month in a plot (/thread-38926.html) |
Sort by month in a plot - ph4n70m1988 - Dec-11-2022 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. |