Multiple Bar Charts in Matplotlib
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
import matplotlib.pyplot as mat
years=[2021,2022,2023,2024,2025]
frooti=[100,350,500,400,700]
limca=[200,400,200,300,500]
pepsi=[600,200,400,700,500]
milk=[700,500,300,500,400]
wd=0.2
f_bar=[0,1,2,3,4]
l_bar=[i+wd for i in f_bar]
p_bar=[i+wd for i in l_bar]
m_bar=[i+wd for i in p_bar]
# print(f_bar)
# print(l_bar)
fc={'family':'Times New Roman','size':30,'color':'r'}
fc1={'family':'Times New Roman','size':25,'color':'g'}
fc2={'family':'Verdana','size':25,'color':'b'}
mat.title("Product Details",fontdict=fc)
# mat.bar(f_bar,frooti,width=wd,color='red',label="Frooti")
# mat.bar(l_bar,limca,width=wd,color='blue',label="Limca")
# mat.bar(p_bar,pepsi,width=wd,color='black',label="Pepsi")
# mat.bar(m_bar,milk,width=wd,color='yellow',label="Milk")
mat.barh(f_bar,frooti,height=wd,color='red',label="Frooti")
mat.barh(l_bar,limca,height=wd,color='blue',label="Limca")
mat.barh(p_bar,pepsi,height=wd,color='black',label="Pepsi")
mat.barh(m_bar,milk,height=wd,color='yellow',label="Milk")
mat.xlabel("Years (0->2021 1->2022 2->2023 .......)",fontdict=fc1)
mat.ylabel("Products",fontdict=fc2)
mat.legend()
mat.show()
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

