14 Feb Matplotlib – Pie Chart
To plot a pie chart in Matplotlib, use the pie() method. Let us see an example wherein we will plot a pie chart for players scoring runs in a match:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import matplotlib.pyplot as plt import numpy as np # Data player = np.array(["Tim", "John", "Amit", "Jacob", "Karl", "Gary"]) score = np.array([85, 59, 99, 77, 67, 95 ]) # Plot a bar graph using the pyplot.bar() method # The 1st parameter is x, the wedge sizes are set here # The labels parameter is the sequence of strings providing the labels for each wedge # The third parameter is autopct, a string that labels the wedges with their numeric value. # The label will be placed inside the wedge. If autopct is a format string, the label will be # fmt % pct plt.pie(score, labels = player, autopct='%1.2f%%') # Display the figure plt.show() |
Output
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
No Comments