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 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
1# Import packages
2import matplotlib.pyplot as plt
3%matplotlib inline
4
5# Create the plot
6fig, ax = plt.subplots()
7
8# Plot with bar()
9ax.bar(x, y)
10
11# Set x and y axes labels, legend, and title
12ax.set_title("Title")
13ax.set_xlabel("X_Label")
14ax.set_ylabel("Y_Label")
15