larw
0
Q:

bar plot 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

# Create a Simple Bar Plot of Three People's Ages

# Create a List of Labels for x-axis
names = ["Brad", "Bill", "Bob"]

# Create a List of Values (Same Length as Names List)
ages = [9, 5, 10]

# Make the Chart
plt.bar(names, ages)

# Show the Chart
plt.show()
1
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
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')

x = ['Nuclear', 'Hydro', 'Gas', 'Oil', 'Coal', 'Biofuel']
energy = [5, 6, 15, 22, 24, 8]

x_pos = [i for i, _ in enumerate(x)]

plt.bar(x_pos, energy, color='green')
plt.xlabel("Energy Source")
plt.ylabel("Energy Output (GJ)")
plt.title("Energy output from various fuel sources")

plt.xticks(x_pos, x)

plt.show()
0
import numpy as npimport matplotlib.pyplot as plt# data to plotn_groups = 4means_frank = (90, 55, 40, 65)means_guido = (85, 62, 54, 20)# create plotfig, ax = plt.subplots()index = np.arange(n_groups)bar_width = 0.35opacity = 0.8rects1 = plt.bar(index, means_frank, bar_width,alpha=opacity,color='b',label='Frank')rects2 = plt.bar(index + bar_width, means_guido, bar_width,alpha=opacity,color='g',label='Guido')plt.xlabel('Person')plt.ylabel('Scores')plt.title('Scores by person')plt.xticks(index + bar_width, ('A', 'B', 'C', 'D'))plt.legend()plt.tight_layout()plt.show()
1
import matplotlib.pyplot as plt
import numpy as np
plt.bar(np.arange(0,100),np.arange(0,100))
-1

New to Communities?

Join the community