BAR MATPLOTLIB code example

Example 1: how to plot a bar using 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()

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

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()

Example 4: matplotlib bar chart

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()

Example 5: how to increase bar width in python matplogtlib

#plt stands for matplotlib.pyplot
#simple way to increase width of a bar in a bar graph
#I will eventually write out another solution for increasing width bars.
#This solution with solve a more complexed problem for increasing width bars in a bar graph.


plt.bar(x, y, width=30)

Example 6: matplotlib bar

# Import packages
import matplotlib.pyplot as plt
%matplotlib inline

# Create the plot
fig, ax = plt.subplots()

# Plot with bar()
ax.bar(x, y)

# Set x and y axes labels, legend, and title
ax.set_title("Title")
ax.set_xlabel("X_Label")
ax.set_ylabel("Y_Label")