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

3 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS