top of page
  • Rohan Dawar

Active Covid-19 Case Rate in Canadian Provinces

Updated: Nov 17, 2020

This is an interactive map published by Health Canada which I have been checking throughout the pandemic to stay updated on the pandemic situation in my country of Canada. The tool displays a map of Canada with statistics overlaying each province. Users can view Count and Rate (/100,000 pop.) of covid-19 total cases, tests, active cases, recoveries and deaths:

Hovering over a province will show a graph of the current statistic being viewed as it played out in that province throughout the course of pandemic so far. For example, here is the active case rate per 100,000 people in Ontario:

What this tool does not show directly is a comparison between the provinces on these statistics, so I grabbed the csv available for download next to the map and read it into a pandas dataframe where I isolated the 'Province' rows into their own sub-dataframes and then plotted their Active Case Rates on the same graph using matplotlib. Here is the result of that:

As we can see, Quebec was reporting an active case rate above 300 until they altered their recovery criteria on July 17th, creating an apparent crash in case rates. Here is a zoomed in graph only showing time since July 17th, and also displaying the most current rate (as of October 28th):

Here is the code that produces the above graph:

#Main Dataframe:
import pandas as pd
df = pd.read_csv('covid19-download.csv', encoding='unicode_escape')

#Plotting - dependencies & lists:
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
province_order = ['Ontario','Quebec','BC','Alberta','Saskatchewan','Manitoba']
cols = ['w','m','g','r','y','c']

#Plotting - plot size & style:
fig, ax = plt.subplots(figsize=(20, 16))
plt.style.use('dark_background');

#Plotting - lines for each province
for province, color in zip(province_order,cols):
    pr_df = df[(df['prname'] == province)]
    plt.plot(pr_df.date, pr_df.rateactive, color)
    
#Plotting - legend & axes
plt.legend(province_order);
plt.ylim(0,180);
plt.xlim('2020-07-17','2020-10-28');
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))

#Plotting - data annotations
for line, name in zip(ax.lines, province_order):
    y = line.get_ydata()[-1]
    ax.annotate(f'{name}-{y}', xy=(1,y), xytext=(6,0), color=line.get_color(), xycoords = ax.get_yaxis_transform(), textcoords="offset points", size=14, va="center")
15 views0 comments

Recent Posts

See All

Comments


bottom of page