1import matplotlib.pyplot as plt
2
3
4# creating the dataset
5data = {'C':20, 'C++':15, 'Java':30,
6 'Python':35}
7courses = list(data.keys())
8values = list(data.values())
9
10
11fig = plt.figure(figsize = (5, 5))
12
13# creating the bar plot
14plt.bar(courses, values, color ='green',
15 width = 0.4)
16
17plt.xlabel("Courses offered")
18plt.ylabel("No. of students enrolled")
19plt.title("Students enrolled in different courses")
20plt.show()
1import matplotlib.pyplot as plt
2
3data = [5., 25., 50., 20.]
4plt.bar(range(len(data)),data)
5plt.show()
6
7// to set the thickness of a bar, we can set 'width'
8// plt.bar(range(len(data)), data, width = 1.)
1import matplotlib.pyplot as plt
2fig = plt.figure()
3ax = fig.add_axes([0,0,1,1])
4langs = ['C', 'C++', 'Java', 'Python', 'PHP']
5students = [23,17,35,29,12]
6ax.bar(langs,students)
7plt.show()
1import numpy as np
2import matplotlib.pyplot as plt
3data = [[30, 25, 50, 20],
4[40, 23, 51, 17],
5[35, 22, 45, 19]]
6X = np.arange(4)
7fig = plt.figure()
8ax = fig.add_axes([0,0,1,1])
9ax.bar(X + 0.00, data[0], color = 'b', width = 0.25)
10ax.bar(X + 0.25, data[1], color = 'g', width = 0.25)
11ax.bar(X + 0.50, data[2], color = 'r', width = 0.25)
1import matplotlib.pyplot as plt
2
3# Create a Simple Bar Plot of Three People's Ages
4
5# Create a List of Labels for x-axis
6names = ["Brad", "Bill", "Bob"]
7
8# Create a List of Values (Same Length as Names List)
9ages = [9, 5, 10]
10
11# Make the Chart
12plt.bar(names, ages)
13
14# Show the Chart
15plt.show()
16
1import matplotlib.pyplot as plt
2import numpy as np
3plt.bar(np.arange(0,100),np.arange(0,100))