0% found this document useful (0 votes)
31 views7 pages

Python Bar Graphs and Charts Tutorial

This document is a Jupyter Notebook created by Tushar Pillai on 24/01/2024. It contains code to plot various graphs using Python libraries like Matplotlib and NumPy. There are 7 questions involving bar graphs, pie charts, scatter plots, and histograms to visualize different datasets on cities, games, expenses, COVID-19 cases, exam scores, and crop yields. For each question, the relevant data is provided and code is written to generate the graph using Matplotlib.

Uploaded by

nameistushar12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views7 pages

Python Bar Graphs and Charts Tutorial

This document is a Jupyter Notebook created by Tushar Pillai on 24/01/2024. It contains code to plot various graphs using Python libraries like Matplotlib and NumPy. There are 7 questions involving bar graphs, pie charts, scatter plots, and histograms to visualize different datasets on cities, games, expenses, COVID-19 cases, exam scores, and crop yields. For each question, the relevant data is provided and code is written to generate the graph using Matplotlib.

Uploaded by

nameistushar12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

Name: Tushar Pillai

Date: 24/01/2024

Roll No: SF04

Practical Name: Graph Plotting-3.


In [42]: frommatplotlib.pyplotimport *

In [22]: fromnumpyimport *

In [24]: frompylabimport *

Q1. Draw the Horizontal Bar Graph for the Follow Data in Maroon
Colour.

In [5]: x=[1,2,3,4,5]
y=[168,190,170,178,195]
barname=('Pune','Mumbai','Nashik','Nagpur','Thane')
bar(x,y,tick_label=barname,color=('m','m','m','m','m'),width=0.5)
title('Bar Graph')
xlabel('cities')
ylabel('Area Index')
show()

Q2. Follow is the info of students participating in various games in a


School. Represent it by a Bar graph with bar width of 0.7 inches.

1 of 7 24/01/24, 12:27
PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

In [9]: x=[1,2,3,4,5]
y=[45,80,54,10,20]
barname=('Cricket','Football','Hockey','Chess','Tennis')
bar(x,y,tick_label=barname,color=('c','r','b','m','m'),width=0.7)
title('Bar Graph')
xlabel('cities')
ylabel('Area Index')
show()

Q3.Using python represent the follow info using a bar graph(in green
colours).

2 of 7 24/01/24, 12:27
PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

In [11]: x=[1,2,3,4,5]
y=[600,4000,2000,1500,700]
barname=('Clothing','Food','Rent','Petrol','Misc')
bar(x,y,tick_label=barname,color=('g','g','g','g','g'),width=0.7)
title('Bar Graph')
xlabel('cities')
ylabel('Area Index')
show()

Q4.Draw the bar graph for the follow Covid-19 data for differ cities.

In [13]: x=[1,2,3,4,5]
y=[5,24,45,32,15]
barname=('Pune','Mumbai','Nagpur','Nashik','Satara')
bar(x,y,tick_label=barname,color=('m','r','c','b','k'),width=0.5)
title('Bar Graph')
xlabel('cities')
ylabel('Area Index')
show()

3 of 7 24/01/24, 12:27
PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

Q5. Using python,Draw a bar graph in GREEN color to present the data
below.

In [16]: x=[1,2,3,4,5]
y=[68,90,70,95,91]
barname=('Maths','Science','English','Marathi','Hindi')
bar(x,y,tick_label=barname,color=('g','g','g','g','g'),width=0.5)
title('Bar Graph')
xlabel('Cities')
ylabel('Area Index')
show()

Q6. Draw the pie-chart for the follow data.

4 of 7 24/01/24, 12:27
PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

In [18]: y=[23,25,22,15,11,4]
barname=('Wheat','Bajra','Rice','Maize','Jowar','Others')
explode=(0,0,0,0.2,0,0)
pie(y,labels=barname,shadow='true',autopct='%1.1f%%',explode=explode)
xlabel('cities')
ylabel('Area Index')
title('Bar Graph')
show()

Q7.Follow table gives aptitude Score(x) and Craetivity (Y). Draw the
Scatter diagram for above data.

In [29]: x=[63,61,62,52,69,55,72,67,80,73]
y=[69,65,67,60,72,62,86,75,82,83]
Graderange=[10,20,30,40,50,60,70,80,90,100]
scatter(Graderange,x,color='g')
scatter(Graderange,y,color='r')
xlabel('Aptitude Score')
ylabel('Creativity')
show()

5 of 7 24/01/24, 12:27
PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

Example 1]

In [30]: x=[63,61,62,52,69]
#y=[69,65,67,60,72]
Graderange=[10,20,30,40,50]
scatter(Graderange,x,color='g')
#scatter(Graderange,y,color='r')
xlabel('Aptitude Score')
ylabel('Creativity')
plt.show()

Example 2]

In [40]: x=[10,20,30,40,50,60,70,80,90,100]
range=[0,100]
y=5
hist(x,y,range,histtype='bar',rwidth=0.8,color='m')
title('Histogarm')
show()

6 of 7 24/01/24, 12:27
PrNo3_SF02_TusharS - Jupyter Notebook http://localhost:8888/notebooks/PrNo3_SF02_TusharS...

In [ ]:

7 of 7 24/01/24, 12:27

You might also like