Table of Contents
To increase the size of the plot in Matplotlib, you can use the figsize parameter inside the pyplot.figure() function. This parameter takes a tuple of the width and height of the plot, both measured in inches. You can also use the set_size_inches() method of the Axes object to manually set the size. Both of these methods will allow you to adjust the size of the plot to your liking.
You can use the following syntax to increase the size of a single plot in Matplotlib:
import matplotlib.pyplot as plt #define figure size in (width, height) for a single plot plt.figure(figsize=(3,3))
And you can use the following syntax to increase the size of all Matplotlib plots in a notebook:
import matplotlib.pyplot as plt #define figure size in (width, height) for all plots plt.rcParams['figure.figsize'] = [10, 7]
The following examples show how to use this syntax in practice.
Example 1: Increase Size of a Single Matplotlib Plot
Suppose we create the following line plot in Matplotlib:
import matplotlib.pyplot as plt #define x and y x = [1, 6, 10] y = [5, 13, 27] #create plot of x and y plt.plot(x, y) plt.show()
By default, the (width, height) of a Matplotlib plot is (6.4, 4.8).
However, we can use the following syntax to increase the plot size to whatever dimensions we’d like:
import matplotlib.pyplot as plt #define plot size plt.figure(figsize=(5,8)) #define x and y x = [1, 6, 10] y = [5, 13, 27] #create plot of x and y plt.plot(x, y) plt.show()
Example 2: Increase Size of All Matplotlib Plots
The following code shows how to set the plot size for all Matplotlib plots in a notebook:
import matplotlib.pyplot as plt #define plot size for all plots plt.rcParams['figure.figsize'] = [10, 4] #define first dataset x = [1, 6, 10] y = [5, 13, 27] #create first plot plt.plot(x, y) plt.show() #define second dataset x2 = [1, 6, 10] y2 = [5, 19, 12] #create second plot plt.plot(x2, y2) plt.show()