🥧 Pie Chart
Last Updated: 06 Nov 2025
Pie chart shows percentage share of categories. Useful when you want to visualize parts of a whole.
. Hinglish Tip 🗣: Pie chart ko “kis cheez ka kitna hissa” dikhane ke liye use karte hain.
Basic Pie Chart
import matplotlib.pyplot as plt
labels = ["A", "B", "C"]
sizes = [40, 35, 25]
plt.pie(sizes, labels=labels)
plt.show()
Useful parameters for Pie Chart
labels- Labels for each slicecolors- Colors for each sliceautopct- Format for percentage labelsexplode- Explode one slice to make it stand outshadow- Add a shadow to the chartstartangle- Starting angle for the chartradius- Radius of the chartcounterclock- Rotate the chart counterclockwisepctdistance- Distance of percentage labels from the centerlabeldistance- Distance of labels from the centertextprops- Text properties for labels
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 7))
labels = ["A", "B", "C", "D"]
sizes = [40, 25, 20, 15]
explode = [0.1, 0, 0, 0] # first slice pulled out
plt.pie(
sizes,
labels=labels,
colors=["skyblue", "orange", "green", "red"],
explode=explode, # highlight a slice
autopct="%1.1f%%", # show % values
shadow=True, # shadow effect
startangle=140, # rotate pie
radius=1.2, # size
textprops={"fontsize": 12} # text styling
)
plt.title("Pie Chart Example")
plt.show()
Hinglish Tip 🗣:
explodeuse karke important slice ko highlight kar sakte ho.
Donut Chart
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 7))
plt.pie(sizes, labels=labels, autopct="%1.1f%%", radius=1.2)
# Draw white circle (center hole)
centre_circle = plt.Circle((0, 0), 0.60, color="white")
plt.gca().add_artist(centre_circle)
plt.title("Donut Chart")
plt.show()
Pie Chart Without Labels
plt.pie(sizes, autopct="%0.2f%%")
plt.show()
Pie Chart With Legend
plt.pie(sizes)
plt.legend(labels, title="Categories")
plt.show()
Comparing Two Pie Charts
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
plt.pie([40, 35, 25], labels=["A", "B", "C"], autopct="%1.1f%%")
plt.title("Pie 1")
plt.subplot(1, 2, 2)
plt.pie([30, 20, 50], labels=["X", "Y", "Z"], autopct="%1.1f%%")
plt.title("Pie 2")
plt.show()