• Home
  • About
  • Services
  • Portfolio
  • Quiz
  • Charts
  • Contact

Bar Plots¶

In [4]:
import matplotlib.pyplot as plt
x=[1,2,3,4]
y=[3,4,5,6]

plt.bar(x,y)
plt.show()
In [5]:
import matplotlib.pyplot as plt
x=[1,2,3,4]
y=[3,4,5,6]
c=['r','c','y','k']
plt.bar(x,y,color=c)
plt.show()
In [6]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
c=['r','c','y','k']
plt.bar(x,y,color=c)
plt.show()
In [10]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)
c=['r','c','y','k']
plt.bar(x,y,color=c,width=0.5)
plt.show()
In [12]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)

plt.bar(x,y,color='y',width=0.5,align='edge')                      # or align='center'
plt.show()
In [13]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)

plt.bar(x,y,color='y',width=0.5,edgecolor='red')  
plt.show()
In [14]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)

plt.bar(x,y,color='y',width=0.5,edgecolor='red',linewidth=5,linestyle=":")  
plt.show()
In [15]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)

plt.bar(x,y,color='y',width=0.5,edgecolor='red',linewidth=5,linestyle=":",alpha=0.4)  
plt.show()
In [18]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)

plt.bar(x,y,color='y',width=0.5,edgecolor='red',label="letters")  
plt.legend()
plt.show()
In [20]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
z=[4,3,2,1]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)

plt.bar(x,y,color='y',width=0.5,label="letter")  
plt.bar(x,z,color='r',width=0.5,label="words")  

plt.legend()
plt.show()
In [37]:
import matplotlib.pyplot as plt
import numpy as np
x=['a','b','c','d']
y=[3,4,5,6]
z=[4,3,2,1]
width=0.2
p=np.arange(len(x))
p1=[j+width for j in p]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)
plt.bar(p1,y,width,color='y',label="letter")  
plt.bar(p,z,width,color='r',label="words")  
plt.xticks(p+width/2,x,rotation=40)
plt.legend()
plt.show()
In [49]:
import matplotlib.pyplot as plt
x=['a','b','c','d']
y=[3,4,5,6]
z=[4,3,2,1]
plt.xlabel('alpha',fontsize=10)
plt.ylabel('values',fontsize=10)
plt.title('Graph',fontsize=10)
width=0.5
plt.barh(x,y,width,color='y',label="letter")  
plt.barh(x,z,width,color='r',label="words")  

plt.legend()
plt.show()