Ads

Python 10 - Create Bar Chart with few lines of code : Python + matplotlib

Hello All,

Good Morning, afternoon, evening what ever zone you are in.

In this article we will learn how to create the bar chart using matplotlib library.   


What is Bar chart?

A bar chart or bar graph presents data with rectangular bars at heights or lengths proportional to the values they represent. The bars can be vertical or horizontal, though they’re usually vertical.

Where we use?

Most probably we use bar chart for financial or market data.

Lets Begin....

1. Create the folder called BarChart

2. Open the folder in VSCode editer

3. Create the python file called students_bar_chart.py

4. install the package matplotlib


5. Next import the file and write the code to generate the bar chart

import matplotlib.pyplot as plt

data ={'Shraddha':95,'tejashree':50,'pooja':35,'abhay':10}

students=list(data.keys())
marks=list(data.values())

fig=plt.figure(figsize=(10,5))

plt.bar(students, marks, color ='pink',
        width = 0.4)
 
plt.xlabel("Students")
plt.ylabel("Marks")
plt.title("Students  and Their Marks")
plt.show()

In the above example we have used static data for bar chart generation

data ={'Shraddha':95,'tejashree':50,'pooja':35,'abhay':10}

That's it lets run the program

Hit the below mentioned command in terminal

python .\students_bar_chart.py

Finally output will be



That's it for now, see you in next article with interesting concepts.

Until then take care bye.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !