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

df.plot.pie(title="Std Mark",y='MATH',figsize=(4,4))
df.plot.pie(title="Std Mark",
y='MATH',fontsize=20)
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)
legend=False

my_explode=(0,0,0.1,0)
df.plot.pie(title="Std Mark",y='MATH',
fontsize=20,explode=my_explode)

my_explode=(1.5,0.0,0.1,0)
df.plot.pie(title="Std Mark",
y='MATH',explode=my_explode)

df.plot.pie(title="Std Mark",y='MATH',
fontsize=20,startangle=40)
df.plot.pie(title="shadow=False",y='MATH',
figsize=(5,5),shadow=False)
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)
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%%')
plot=df.plot.pie(title="Colors",y='MATH',autopct='%1.1f%%')
fig = plot.get_figure()
fig.savefig("D:\\my_data\\output2.png")
Pandas plot
Line plot
Bar plot
Box plot
Density plot
Area plot
Scatter Plot
Hexbin plot
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.