In this article I am going to show you how to visualize covid-19 pandemic using python libraries.
At the end of this article you will get this result:

The libraries used for making this output are:
Numpy
It is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.
Pandas
pandas is a software library written for the Python programming language for data manipulation and analysis.
Plotly
The Plotly Python library is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases.
Built on top of the Plotly JavaScript library.
Plotly Express
It is a new high-level Python visualization library. it’s a wrapper for Plotly.py that exposes a simple syntax for complex charts.
Graph_objs
This package imports definitions for all of Plotly’s graph objects.
The reason for the package graph_objs and the module graph_objs is to provide a clearer API for users.
In the source code below, I focused on recovered cases for just one day, which at 9/04/2020.
# Import libraries
import numpy as np
import pandas as pd
import plotly as py
import plotly.express as px
import plotly.graph_objs as go
from plotly.subplots import make_subplots
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
# Load data frame and tidy it
df = pd.read_csv('time_series_covid_19_recovered.csv')
#convert the column '4/9/2020' type to string
df['4/9/2020'].apply(str)
# Rename columns
df = df.rename(columns={'Country/Region':'Country'})
df = df.rename(columns={'4/9/2020':'Date'})
# Create the Choropleth
fig = go.Figure(data=go.Choropleth(
locations=df['Country'], # Spatial coordinates
z = df['Date'], # Data to be color-coded
locationmode = 'country names', # set of locations match entries in `locations`
colorscale = 'Viridis',
marker_line_color = 'black',
marker_line_width = 0.5,
))
fig.update_layout(
title_text = 'Covid-19 recovered cases for the day 09/4/2020',
title_x = 0.5,
geo=dict(
showframe = False,
showcoastlines = False,
projection_type = 'equirectangular'
)
)
fig.show()
To get a dynamic choropleth maps,you should make the update mentioned in the code below:
# Import libraries
import numpy as np
import pandas as pd
import plotly as py
import plotly.express as px
import plotly.graph_objs as go
from plotly.subplots import make_subplots
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
# Load data frame and tidy it
df = pd.read_csv('time_series_covid_19_recovered.csv')
#convert the column '4/9/2020' type to string
df['4/9/2020'].apply(str)
# Rename columns
df = df.rename(columns={'Country/Region':'Country'})
df = df.rename(columns={'4/9/2020':'Date'})
# Creating the visualization
#start of the update
fig = px.choropleth(df,
locations="Country",
locationmode = "country names",
color="Date",
hover_name="Country",
animation_frame="Date"
)
#end of the update
fig.update_layout(
title_text = 'Covid-19 recovered cases for the day 09/4/2020',
title_x = 0.5,
geo=dict(
showframe = False,
showcoastlines = False,
))
fig.show()
The output:

Conclusion:
A choropleth maps displays divided geographical areas or regions that are coloured in relation to a numeric variable.
It allows to study how a variable evolutes along a territory.
It is a powerful and widely used data visualization technique.
However, its downside is that regions with bigger sizes tend to have a bigger weight in the map interpretation, which includes a bias.
Resources