Bar Plot

Bar Plot : 

import matplotlib.pyplot as plt 

a = ["math","science","english"]
b = [60,70,80]
plt.bar(a,b)
plt.show()
Horizontal bar plot : 

import matplotlib.pyplot as plt 

a = ["math","science","english"]
b = [60,70,80]
plt.barh(a,b)
plt.show()
Customizing Bar Plot : 

import matplotlib.pyplot as plt 

a = ["math","science","english"]
b = [60,70,80]
fig = plt. figure( figsize = (10,5) )
plt.bar(a,b,color = "green",alpha = 0.8)
plt.legend(["marks"] , loc = "best")
plt.xlabel("Subject")
plt.ylabel("marks")
plt.show()
Adding Two Bar Plot : 

import matplotlib.pyplot as plt 

a = ["math","science","english"]
b = [60,70,80]

a1= [" marathi" ,"algebra", "history", "geography"]

b1= [40,55,65,85]

fig = plt. figure( figsize = (10,5) )
x = plt. subplot(1,2,1)

plt.bar(a,b,color = "green",alpha = 0.7)

plt.legend(["marks"] , loc = "best")

y = plt. subplot(1,2,2)

plt.bar(a1,b1,color = "red",alpha = 0.7)

plt.legend(["marks"] , loc = "best")

plt.show()
Bar Plot : 

import matplotlib.pyplot as plt 

data = { "mango" : 1000, "apple" : 200, "banana": 100}

x= list(data.keys())
y =list(data.values())

plt.bar(x, y)
plt.show()

Comments

Popular posts from this blog

Python Tokens

Pie Chart , Donut Plot, Area plot