Matplotlib Pie Chart: Create a pie chart of the popularity of programming Languages
Matplotlib Pie Chart: Exercise-1 with Solution
Write a Python programming to create a pie chart of the popularity of programming Languages.
Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++
Popularity: 22.2, 17.6, 8.8, 8, 7.7, 6.7
Sample Solution:
Python Code:
import matplotlib.pyplot as plt
# Data to plot
languages = 'Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++'
popuratity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b"]
# explode 1st slice
explode = (0.1, 0, 0, 0,0,0)
# Plot
plt.pie(popuratity, explode=explode, labels=languages, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)
plt.axis('equal')
plt.show()
Sample Output:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Matplotlib Pie Chart Exercises
Next: Write a Python programming to create a pie chart with a title of the popularity of programming Languages.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/graphics/matplotlib/piechart/matplotlib-piechart-exercise-1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics