How to Plot Multiple Bars in Single Bar Graph in Matplotlib

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

import matplotlib.pyplot as mat
years=[2019,2020,2021,2022,2023]
frooti=[300,500,200,600,400]
pepsi=[300,200,400,500,350]
limca=[400,200,300,600,500]
wd=0.2
f_bar=[0,1,2,3,4]
#print(f_bar)
p_bar=[i+wd for i in f_bar]
l_bar=(i+wd for i in p_bar)
#print(p_bar)
mat.bar(f_bar,frooti,width=wd,color='red',label="Frooti")
mat.bar(p_bar,pepsi,width=wd,color='blue',label="Pepsi")
mat.bar(l_bar,limca,width=wd,color='yellow',label="Limca")
mat.title("Produt Details(5 Year)")
mat.legend()
mat.show()

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses
Image

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *