Change Figure Size in Matplotlib
Introduction
Matplotlib is one of the most widely used data visualization libraries in Python. Much of Matplotlib’s popularity comes from its customization options – you can tweak just about any element from its hierarchy of objects.
In this tutorial, we’ll take a look at how to change a figure size in Matplotlib.
Creating a Plot
Let’s first create a simple plot in a figure:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 10, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()
Here, we’ve plotted a sine function, starting at 0
and ending at 10
with a step of 0.1
. Running this code yields:
The Figure
object, if not explicitly created, is created by default and contains all the elements we can and cannot see. Changing the size of the Figure
will in turn change the size of the