Matplotlib Tutorial
Immediately, I’ll present you create a lipstick chart for visualizing progress on metrics the place the decrease the worth, the higher.
It’s good when metrics have comparable traits and subjects however not the identical scale. My goal is to share a message reasonably than “simply” a plot.
I’ve ready a easy dataset about mortality and illnesses so as to deal with creating the visualization.
The info comes from the World Bank and is publicly out there beneath Inventive Commons licenses. If you wish to study extra, I’ve written concerning the visualization in my new free publication, Data Wonder.
Let’s get began.
Step 1 – Importing libraries
The primary and easiest half is to import the required libraries like pandas and matplotlib.
import numpy as np
import pandas as pdimport seaborn as sns
import matplotlib.pyplot as plt
from PIL import Picture
from matplotlib.strains import Line2D
Congratulations, you simply accomplished step 1! 🥳
Step 2 — Create a Seaborn type
Subsequent, I wish to create a colour scheme and choose a font. Websites like Coolors and Colorhunt are nice assets when trying to find lovely colours.
Right here’s my code and settings to create the seaborn type for this tutorial.
FONT_FAMILY = "serif"
BACKGROUND_COLOR = "#FAE8E0"
TEXT_COLOR = "#33261D"
BAR_COLOR = "#EF7C8E"sns.set_style({
"axes.facecolor": BACKGROUND_COLOR,
"determine.facecolor": BACKGROUND_COLOR,
"textual content.colour": TEXT_COLOR,
"font.household": FONT_FAMILY,
"xtick.backside": False,
"xtick.high": False,
"ytick.left": False,
"ytick.proper": False,
"axes.spines.left": False,
"axes.spines.backside": False,
"axes.spines.proper": False,
"axes.spines.high": False,
})
I’m eradicating all of the ticks and features to create a clear visualization, and the grids don’t add invaluable data to our lipstick chart.