Skip to content

Instantly share code, notes, and snippets.

@trombonehero
Last active April 11, 2020 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trombonehero/b7b2ec2667dab2bf3bb09399984a8046 to your computer and use it in GitHub Desktop.
Save trombonehero/b7b2ec2667dab2bf3bb09399984a8046 to your computer and use it in GitHub Desktop.
Simple (but grim) example of using Matplotlib and Pandas for data visualization
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