14 Feb Matplotlib – Bar Graph
To plot a bar graph in Matplotlib, use the bar() method. Let us see an example wherein we will plot a bar graph for student and student marks:
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 # x and y coordinates student = np.array(["Tim", "John", "Amit", "Jacob", "Karl", "Gary"]) marks = np.array([85, 59, 99, 77, 67, 95 ]) # Plot a bar graph using the pyplot.bar() method # The x and y coordinates below are the student and marks respectively plt.bar(student, marks) # The labels for x-coordinate and y-coordinate plt.xlabel("Student") plt.ylabel("Marks") # 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