Python Forum
Sort by month in a plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sort by month in a plot
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Changing Time Series from Start to End of Month illmattic 0 1,869 Jul-16-2020, 10:49 AM
Last Post: illmattic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020