Screen Link:
My Code:
header_row = ['City', 'Event', 'Date', 'Injuries']
list_of_list = [['Fairfax', 'Protest', '09 May 2020', '4'], ['Herndon', 'Disturbance', '09 May 2020', '2'], ['Reston', 'Protest', '09 May 2020', '4'], ['Vienna', 'Gathering', '10 May 2020', '3'], ['McLean', 'Gathering', '11 May 2020', '4'], ['Falls Church', 'Disturbance', '15 May 2020', '3']]
dates, injuries = [], []
for row in list_of_list:
current_date = dt.datetime.strptime(row[2], '%d %b %Y')
hurt = int(row[3])
dates.append(current_date)
injuries.append(hurt)
import matplotlib.pyplot as plt
plt.style.use('seaborn')
fig, ax = plt.subplots()
ax.plot(dates, injuries, c='red')
ax.set_title('Daily Injuries, May 2020', fontsize=24)
ax.set_xlabel('', fontsize=16)
fig.autofmt_xdate()
ax.set_ylabel("Injuries", fontsize=16)
ax.tick_params(axis='both', which='major', labelsize=16)
plt.show()
What I expected to happen:
What actually happened: My dataset contains individual entries (rows) for every event. So if 10 things happened on 9 May, I will have 10 different entries (rows) for 9 May. When I display the data, I get these vertical lines on days that had several events. I wonder if there’s a way to combine days with several events, so that the visualization reflects the total number of events for that day.
For instance, in the above dataset, three events occurred on 09 May. Therefore, the visualization has a vertical line for 9 May. It looks odd, and the visualization doesn’t showcase the total number for that day, because of the vertical line.
[image|614x500](upload://mCXQiX1NE5EskWsusaLkXQWYJ6G.png)