plt bar plot code example
Example 1: how to plot a bar using matplotlib
import matplotlib.pyplot as plt
data = {'C':20, 'C++':15, 'Java':30,
'Python':35}
courses = list(data.keys())
values = list(data.values())
fig = plt.figure(figsize = (5, 5))
plt.bar(courses, values, color ='green',
width = 0.4)
plt.xlabel("Courses offered")
plt.ylabel("No. of students enrolled")
plt.title("Students enrolled in different courses")
plt.show()
Example 2: bar plot matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
ax.bar(langs,students)
plt.show()
Example 3: matplotlib bar chart
import matplotlib.pyplot as plt
names = ["Brad", "Bill", "Bob"]
ages = [9, 5, 10]
plt.bar(names, ages)
plt.show()
Example 4: bar plot python
import matplotlib.pyplot as plt
import numpy as np
plt.bar(np.arange(0,100),np.arange(0,100))