Last active
April 11, 2020 20:21
-
-
Save trombonehero/b7b2ec2667dab2bf3bb09399984a8046 to your computer and use it in GitHub Desktop.
Simple (but grim) example of using Matplotlib and Pandas for data visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import pandas as pd | |
# | |
# Read data and compute some summaries: | |
# | |
data = pd.read_csv('covid-data.csv') | |
data['Total'] = data['New'].cumsum() | |
data['Deceased'] = data['Deaths'].cumsum() | |
data['Recovered'] = data['Recoveries'].cumsum() | |
data['Hospitalized'] = data['Hospitalizations'].cumsum() | |
data['Active'] = data['Total']-data['Recovered']-data['Deceased'] | |
# | |
# Construct two plots: one for daily accumulation (new vs total) | |
# and one for active vs recovered, etc. | |
# | |
fig, ax = plt.subplots(2, constrained_layout=True) | |
fig.suptitle('COVID-19 cases in Newfoundland and Labrador', | |
fontsize=14, fontweight='bold') | |
data.plot.area(ax=ax[0], x='Date', y=['Deceased', 'Recovered', 'Active'], | |
color=['dimgrey', 'mediumturquoise', 'lightcoral'], | |
title='Total cases by category') | |
data.plot(ax=ax[1], x='Date', y=['Total', 'New'], title='New and total cases') | |
# Show the results! | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment