Easier subplots layout with Python's Matplotlib

How to simplify one of Matplotlib's most tedious tasks

Thiago Carvalho
4 min readMay 31, 2022

Arranging subplots, texts, and annotations can quickly become a frustrating task in Matplotlib. Often, you may find yourself guessing the coordinates and making multiple minor adjustments to find the right place for your elements.

It's ok to have some pattern or logic to guide you through. Things like labelling bars with their values or plotting multiple visualizations with the same size are easy to implement. But moving texts, the legend, or subplots to arbitrary places can quickly become tedious.

This article will explore Pylustrator, a simple package that provides a UI to adjust Matplotlib charts, making the final touches to your visualizations that much easier.

Let's start small; we'll plot four charts and check how to start using Pylustrator with two lines of code.

import matplotlib.pyplot as pltfig, ((ax,ax1),(ax2,ax3)) = plt.subplots(2,2,figsize=(8,8))ax.plot([1,2,3,4,5,6], [10,15,20,30,25,40])
ax1.bar(['a','b','c','d','e'],[10,20,10,5,3])
ax2.pie([3,3,3,3])
ax3.scatter([1,1,4,4,2,3,2.5], [1,4,4,1,2,2,3])
plt.show()

--

--