AI

# Tips on how to Create Hexagon Maps With Matplotlib | by Oscar Leo | Nov, 2023

## Utilizing shapes to symbolize geographic data

Let’s make some maps! 🗺

Hello, and welcome to a brand new matplotlib tutorial. This time, I’ll train you the right way to create insightful Hexagon maps just like the one above.

Visualizing geographic data is troublesome as a result of areas (corresponding to 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 troublesome so as to add data corresponding to nation names or values to your visualizations.

Another that removes such variations is to make use of a hexagon map.

The thought is to symbolize every space as a hexagon and prepare them in a approach that resembles the precise map.

Since every hexagon is similar in form, it’s simple so as to add data in a structured approach and to create a good looking knowledge visualization.

This tutorial teaches you the right way to do exactly that utilizing knowledge from the presidential elections in america.

(Don’t overlook to take a look at my other Matplotlib tutorials as properly)

Let’s get began. 🚀

## Step 1: Import libraries

We begin by importing the required libraries.

`import pandas as pdfrom matplotlib.patches import Polygonimport matplotlib.pyplot as pltimport seaborn as snsimport matplotlib.patheffects as PathEffects`

That’s it.

## Step 2: Create a seaborn fashion

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"sns.set_style({"axes.facecolor": background_color,"determine.facecolor": background_color,"font.household": font_family,})`

FYI: I typically use `background_color="#00000000"` to get a clear background if I need to add the chart to an infographic or related.

Check Also
Close