Hi, and welcome to this Python + Matplotlib tutorial, where I will show you how to create the beautiful polar histogram you see above.
Polar histograms are great when you have too many values for a standard bar chart. The circular shape where each bar gets thinner towards the middle allows us to cram more information into the same area.
A nice feature is the resulting visual comparison between the lowest and highest values as they meet each other after one lap around the center.
My data frame contains 146 countries and three columns.
Here’s what it looks like.
I’ll show and explain every line of code required to create the visualization. If you want to follow along, you can find the code and data I’m using in this GitHub repository.
Let’s get started.
We only need standard Python libraries familiar to everyone. PIL is not mandatory, but it’s my preferred choice for handling images which we do when adding flags.
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from PIL import Image
from matplotlib.lines import Line2D
from matplotlib.patches import Wedge
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
The only thing that stands out is a few specific Matplotlib imports at the end. I’ll cover those components later in the tutorial.
As usual, I use pandas to load the data.