Sure, I created the map above utilizing Matplotlib, and I’ll present you the way on this tutorial.
The concept is to create a reusable and versatile operate that enables me to immediately draw an attractive map of any space.
With such a operate, I can save a ton of time after I need to create charts or infographics with a geographical part.
I additionally need to present the ability of reusable code since many programmers working with knowledge visualization neglect about such finest practices.
This tutorial incorporates each single line of code it’s essential create the map of Africa above.
Let’s get began.
Step 1: Obtain geo knowledge
The one factor it’s essential do earlier than you can begin the tutorial is to obtain geo knowledge from right here:
It’s the official boundaries from the World Financial institution and a public dataset you need to use nevertheless you need.
Step 2: Import libraries
As common, we begin by importing the mandatory libraries, and we don’t want many. Since we have now geographical knowledge, we would like
geopandas to make plotting as straightforward as attainable.
import numpy as np
import pandas as pd
import seaborn as sns
import geopandas as gpd
import matplotlib.pyplot as plt
import matplotlib.patheffects as PathEffects
from matplotlib.patches import Polygon
One import that you just might need but to see is
PathEffe. I’ll use that to create a border across the nation labels later.
Step 3: Create a seaborn type
Earlier than plotting, I all the time create a seaborn type to get a coherent look. Right here, I solely outline a
text_color. I’m setting the background to mild blue to symbolize the ocean.
font_family = "sans"
background_color = "#D4F1F4"
text_color = "#040303"