Matplotlib Bar Chart: Display a horizontal bar chart of the popularity of programming Languages
Matplotlib Bar Chart: Exercise-2 with Solution
Write a Python programming to display a horizontal bar 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
x = ['Java', 'Python', 'PHP', 'JS', 'C#', 'C++']
popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
x_pos = [i for i, _ in enumerate(x)]
plt.barh(x_pos, popularity, color='green')
plt.xlabel("Popularity")
plt.ylabel("Languages")
plt.title("PopularitY of Programming Language\n" + "Worldwide, Oct 2017 compared to a year ago")
plt.yticks(x_pos, x)
# Turn on the grid
plt.minorticks_on()
plt.grid(which='major', linestyle='-', linewidth='0.5', color='red')
# Customize the minor grid
plt.grid(which='minor', linestyle=':', linewidth='0.5', color='black')
plt.show()
Sample Output:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python programming to display a bar chart of the popularity of programming Languages.
Next: Write a Python programming to display a bar chart of the popularity of programming Languages. Use uniform color.
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/barchart/matplotlib-barchart-exercise-2.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics