Amory
0
Q:

how to plotting bar on matplotlib

import matplotlib.pyplot as plt  
  
   
# creating the dataset 
data = {'C':20, 'C++':15, 'Java':30,  
        'Python':35} 
courses = list(data.keys()) 
values = list(data.values()) 
   

fig = plt.figure(figsize = (5, 5)) 
  
# creating the bar plot 
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() 
1
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.)
0
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()
1

New to Communities?

Join the community