bar graph python python 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: how to plotting bar on matplotlib
import matplotlib.pyplot as plt
data = [5., 25., 50., 20.]
plt.bar(range(len(data)),data)
plt.show()
// to set the thickness of a bar, we can set 'width'
// plt.bar(range(len(data)), data, width = 1.)
Example 3: bar chart in python
import numpy as npimport matplotlib.pyplot as plt
Example 4: bar chart in python
import matplotlib.pyplot as plt; plt.rcdefaults()import numpy as npimport matplotlib.pyplot as pltobjects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')y_pos = np.arange(len(objects))performance = [10,8,6,4,2,1]plt.bar(y_pos, performance, align='center', alpha=0.5)plt.xticks(y_pos, objects)plt.ylabel('Usage')plt.title('Programming language usage')plt.show()