20 C
London
Wednesday, July 23, 2025
HomePandas in PythonGeneral Functions in PythonHow to Adjust the Figure Size of a Pandas Plot

How to Adjust the Figure Size of a Pandas Plot

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 figsize parameter to quickly adjust the figure size of a plot in pandas:

df.plot.scatter(x='x', y='y', figsize=(8,4))

The first value in the figsize parameter specifies the width and the second value specifies the height of the plot.

The following examples show how to use this parameter in practice with the following pandas DataFrame:

import pandas as pd

#create DatFrame
df = pd.DataFrame({'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                   'y': [5, 7, 7, 9, 10, 14, 13, 15, 19, 16]})

#view head of DataFrame
df.head()

        x	y
0	1	5
1	2	7
2	3	7
3	4	9
4	5	10

Example 1: Create Plot with Default Size

The following code shows how to create a scatter plot in pandas using the default plot size:

#create scatter plot with default size
df.plot.scatter(x='x', y='y')

Example 2: Create Horizontal Plot

The following code shows how to create a scatter plot in pandas in which the width is twice as long as the height:

#create scatter plot with longer width than height
df.plot.scatter(x='x', y='y', figsize=(8,4))

Notice that the plot is much wider than it is tall.

Example 3: Create Vertical Plot

The following code shows how to create a scatter plot in pandas in which the height is twice as long as the width:

#create scatter plot with longer height than width 
df.plot.scatter(x='x', y='y', figsize=(4,8))

Notice that the plot is much taller than it is wide.

Additional Resources

The following tutorials explain how to perform other common tasks in pandas:

Pandas: How to Add Titles to Plots
Pandas: How to Create Plot Legends
Pandas: How to Create Bar Plot from GroupBy

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