Customizing Matplotlib With Stylesheets

@lee-rowe
Geek Culture
Published in
4 min readAug 1, 2021

--

Photo by Kelli Tungay on Unsplash

With Matplotlib comes the ability to create static, animated, and interactive visualizations in Python. Below is a randomly generated sample using the package, although it isn’t necessarily bad looking using this package will allow you to choose from several different built-in styles. In this short blog post I will discuss the many different ways to customize your Matplotlib visualizations. To get started with this example, we will need to import a few packages. This can be done using the code in the cell found below.

import matplotlib as plt
import seaborn as sns

Once you have these basic libraries installed, we can then use them to generate some sample graphs to demonstrate the functionalities that Matplotlib is capable of.

def hist_and_lines():
np.random.seed(0)
fig, ax = plt.subplots(1, 2, figsize=(11, 4))
ax[0].hist(np.random.randn(1000))
for i in range(3):
ax[1].plot(np.random.rand(10))
ax[1].legend(['a', 'b', 'c'], loc='lower left')
hist_and_lines()

Starting first with the fivethirtyeight style, which mimics the graphics found on the popular FiveThirtyEight website. As you can see here, it is typified by bold…

--

--