Python package that I will be using:

The Python package I would be using is Cartopy. It was initially developed at the UK Met office so that scientists could visualize their data accurately. Cartopy makes use of PROJ.4NumPy and Shapely libraries, and has an interface built on top of Matplotlib.

Sample Data

The sample data is COVID-19 data that has been downloaded from the following website. It contains the Latitude and Longitude data of every Country affected by COVID-19, along with the number of cumulative cases each day.

Preview of the Data

Image for post

This what the data looks like

Extracting Latitude and Longitude

We need to extract the list of latitude and longitude from the above data in such a way that the list is in order, starting from the Country, which showed the 1st COVID-19 case.

In the code given below, for every data column, we are iterating over all the rows, to check if the value for that particular row and column is ZERO or not. If the value is not equal to zero, the corresponding latitude and longitude get appended, thus ensuring the list of latitude and longitudes to be in the order of occurrence of COVID-19 for that particular Country. Since the same latitude and longitude would get appended numerous times, we change their value to 500 (to such a value that won’t be possible for latitude or longitude to possess) so that it is easier to remove them from the list later.

list_lat= []
list_long = []

for i in range(3, 193):
    for k in range(data.shape[0]):
        if(int(data.iloc[k, i]) != 0):
            list_lat.append(data.iloc[k, 1])
            list_long.append(data.iloc[k, 2])
#Change the already appended values to a different value
            data.iloc[k, 1] = 500 
            data.iloc[k, 2] = 500
        else:
            continue

list_lat[0:5] 
list_long[0:5]
#Removing the 500s from the list
#Latitude
for i in range(list_lat.count(500)):
    list_lat.remove(500)
#Longitude
for i in range(list_long.count(500)):
    list_long.remove(500)

Creating the Cartopy Map

#Installing Cartopy
pip install cartopy

#Importing required libraries
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import matplotlib.pyplot as plt
import cartopy.mpl.geoaxes
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from matplotlib.animation import FuncAnimation

#data #maps #animation #python

How to Create Map Animations using Python
29.35 GEEK