Thursday, August 28, 2025
HomeLanguagesChange figure size in Pandas – Python

Change figure size in Pandas – Python

Prerequisites: Pandas

The size of a plot can be modified by passing required dimensions as a tuple to the figsize parameter of the plot() method. it is used to determine the size of a figure object.

Syntax:

figsize=(width, height)

Where dimensions should be given in inches.

Approach

  • Import pandas.
  • Create or load data
  • Call the plot() function with a figsize parameter along with dimensions.

Example 1

Python3




import pandas as pd  # import the pandas module
  
# python list of numbers
data1 = [10, 20, 50, 30, 15]
  
# convert the list to a pandas series
s1 = pd.Series(data1)  
  
# creates a figure of size 20 inches wide and 10 inches high
s1.plot(figsize=(20, 10))


Output:

Example 2

Python3




# import the pandas module
import pandas as pd  
  
# Creating a pandas dataframe
df = pd.DataFrame({'names': ['A', 'B', 'C', 'D'], 'val': [10, 45, 30, 20]})
  
# creates a bar graph of size 15 inches wide and 10 inches high
df.plot.bar(x='names', y='val', rot=0, figsize=(15, 10))


Output :

Example 3

Python3




# import the pandas module
import pandas as pd
  
# Creating a pandas dataframe with index
df = pd.DataFrame({'value': [3.330, 4.87, 5.97]},
                  index=['Item 1', 'Item 2', 'Item 3'])
  
df.plot.pie(y='value', figsize=(5, 5))


Output :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32236 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6609 POSTS0 COMMENTS
Nicole Veronica
11779 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11828 POSTS0 COMMENTS
Shaida Kate Naidoo
6719 POSTS0 COMMENTS
Ted Musemwa
7002 POSTS0 COMMENTS
Thapelo Manthata
6678 POSTS0 COMMENTS
Umr Jansen
6690 POSTS0 COMMENTS