Let’s make some maps! 🗺
Hello, and welcome to a brand new matplotlib tutorial. This time, I’ll educate you how one can create insightful Hexagon maps just like the one above.
Visualizing geographic info is tough as a result of areas (reminiscent of international locations) range in dimension and form.
The result’s that some areas are laborious to see if you plot your knowledge utilizing common maps.
It’s additionally tough so as to add info reminiscent of nation names or values to your visualizations.
Another that removes such variations is to make use of a hexagon map.
The thought is to signify every space as a hexagon and prepare them in a manner that resembles the precise map.
Since every hexagon is equivalent in form, it’s straightforward so as to add info in a structured manner and to create a lovely knowledge visualization.
This tutorial teaches you how one can do exactly that utilizing knowledge from the presidential elections in the US.
(Don’t overlook to have a look at my other Matplotlib tutorials as effectively)
Let’s get began. 🚀
Step 1: Import libraries
We begin by importing the required libraries.
import pandas as pd
from matplotlib.patches import Polygon
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.patheffects as PathEffects
Step 2: Create a seaborn type
Subsequent, we use seaborn to set the background and font household. I’m utilizing
Work Sans and
#F4EBCD, however be at liberty to experiment.
font_family = "Work sans"
background_color = "#E0E9F5"
FYI: I usually use
background_color="#00000000" to get a clear background if I wish to add the chart to an infographic or comparable.