# Easier subplots layout with Python's Matplotlib

## How to simplify one of Matplotlib's most tedious tasks

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()

Once we've installed the package, we need to import and use the start statement function at the beginning of our code. — pip install pylustrator

import matplotlib.pyplot as plt
import pylustrator
pylustrator.start()fig, ((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()

There it is. You can customize the figure size, background color, add texts, and drag and drop subplots and…