[ad_1]
Matplotlib Tutorial
How to attract stunning maps with Python and Matplotlib
Sure, I created the map above utilizing Matplotlib, and I’ll present you ways on this tutorial.
The thought is to create a reusable and versatile operate that permits me to immediately draw a wonderful map of any space.
With such a operate, I can save a ton of time after I wish to create charts or infographics with a geographical part.
I additionally wish to present the facility of reusable code since many programmers working with knowledge visualization neglect about such greatest practices.
This tutorial incorporates each single line of code you might want to create the map of Africa above.
Let’s get began.
Step 1: Obtain geo knowledge
The one factor you might want to do earlier than you can begin the tutorial is to obtain geo knowledge from right here:
World Boundaries GeoJSON — Very Excessive Decision
It’s the official boundaries from the World Financial institution and a public dataset you should use nevertheless you need.
Step 2: Import libraries
As normal, we begin by importing the mandatory libraries, and we don’t want many. Since now we have geographical knowledge, we would like geopandas to make plotting as straightforward as attainable.
import numpy as npimport pandas as pdimport seaborn as snsimport geopandas as gpdimport matplotlib.pyplot as plt
import matplotlib.patheffects as PathEffectsfrom matplotlib.patches import Polygon
One import that you simply may 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 at all times create a seaborn type to get a coherent look. Right here, I solely outline a background_color, font_family, and text_color. I’m setting the background to gentle blue to signify the ocean.
font_family = “sans”background_color = “#D4F1F4″text_color = “#040303”
sns.set_style({“axes.facecolor”: background_color…
[ad_2]
Source link