Python Charts

Python plotting and visualization demystified

Changing the Figure and Plot Size in Matplotlib

How to change the figure and plot size in Matplotlib

Updating All Figure Sizes with rcParams

If you want to change the figure size for all your plots, the best thing to do is update Matplotlib's rcParams. You can see a list of all rcParams settings in the Matplotlib documentation.

Figure size is set in inches and the default is 6.4 (width) x 4.8 (height). To update this, simply change the rcParams:

import matplotlib as mpl
import matplotlib.pyplot as plt

# You can do either of these.
mpl.rcParams['figure.figsize'] = (9, 6)
plt.rcParams['figure.figsize'] = (9, 6)

That will increase the size of all the plots in the rest of your script.

matplotlib larger figure size example

Updating Figure Size Per Plot

You can also update individual plots quite easily using a few different approaches.

plt.figure

import matplotlib.pyplot as plt

plt.figure(figsize=(9, 6))
# I'm big!
plt.plot(range(5), range(5))

fig.set_size_inches

This method does the same thing. It can be useful if you have access to the plot (axes) but not the figure.

import matplotlib.pyplot as plt

# I'm big!
plt.plot(range(5), range(5))
fig = plt.gcf()
fig.set_size_inches(9, 6)

plt.subplots

This is the object-oriented approach using plt.subplots. Very similar and simple as well.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(9, 6))
# I'm big!
ax.plot(range(5), range(5))

That's it! Change the figure size is super easy in Matplotlib, but also one of those things that's easy to forget. Feel free to bookmark this page ;)