Pandas DataFrame Plot pie graph

Pandas plot

Pandas.DataFrame.plot to generate pie using data
DataFrame pie chart
import pandas as pd 
my_dict={
'NAME':['Ravi','Raju','Alex','Ronn'],
'MATH':[30,40,50,50]
}
df = pd.DataFrame(data=my_dict)
df.plot.pie(title="Std Mark",y='MATH')

pie chart with options

There are several options we can add to above pie diagram.

figsize :

figsize=(4,4)
Size of the graph , it is a tuple saying width and height in inches, figsize=(6,3). Here width is 6 inches and height is 3 inches. Since our pia chart is a circle so better to use equal width and height.
df.plot.pie(title="Std Mark",y='MATH',figsize=(4,4))

fontsize

fontsize=20 , we can set the font size used labels in x and y axis. fontsize=20
df.plot.pie(title="Std Mark",
y='MATH',fontsize=20)

labels

lables option for pia diagram We can define our labels by using list.
my_labels=['Ravi','Raju','Alex','Ronn']
df.plot.pie(title="Std Mark",y='MATH',
            fontsize=20,labels=my_labels)

explode

We can add option to explode one segment by using a tuple. explode option for pia diagram
my_explode=(0,0,0.1,0)
df.plot.pie(title="Std Mark",y='MATH',
        fontsize=20,explode=my_explode)

We can change the value ( from 0 ) to move the segments more distance. Here we are moving the first segment more. explode option for pia diagram
my_explode=(1.5,0.0,0.1,0)
df.plot.pie(title="Std Mark",
 y='MATH',explode=my_explode)

startangle

startangle option for pia diagram
We can add option startangle=40 to give the initial starting point for the first segment. 0 degree is the base from which anti clock wise the angle is checked.
df.plot.pie(title="Std Mark",y='MATH',
        fontsize=20,startangle=40)

shadow=True


shadow=True option for pie diagram shadow=False option for pie diagram








df.plot.pie(title="shadow=False",y='MATH',
        figsize=(5,5),shadow=False)

colors

colors option for pie diagram We can use the option colors to give different colors to segments. We can use one tuple to define the colours.
my_colors=['lightblue','lightgreen',
           'silver','green']
df.plot.pie(title="Colors",y='MATH',
        figsize=(5,5),colors=my_colors)

autopct

autopct option for pie diagram To display the percentage of each segment we can define the format. Here is one sample to show one decimal place autopct='%1.1f%%' , for two decimal places it can be autopct='%1.2f%%'
df.plot.pie(title="Colors",y='MATH',
        autopct='%1.1f%%')
Pandas plot plot.barh()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer