13.2 C
London
Tuesday, July 2, 2024
HomePythonMatplotlib in PythonHow to Increase Plot Size in Matplotlib

How to Increase Plot Size in Matplotlib

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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

Notice that both plots have the width and height specified by the rcParams arguments.

Additional Resources

How to Adjust Marker Size in Matplotlib
How to Change Font Sizes in Matplotlib
How to Adjust Line Thickness in Matplotlib

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories