1. Create a horizontal bar graph of following data.
Add suitable
labels.
City Population
Delhi 23456123
Mumbai 20083104
Bangalore 18456123
Hyderabad 13411093
Ans:
import numpy as np import [Link] as plt
Cities = [‘Delhi’, ’Mumbai’, ’Bangalore’, ’Hyderabad’]
Population = [23456123, 20083104, 18456123, 13411093]
[Link](Cities, Population]
plt. ylabel(‘Cities’)
[Link](‘Population’)
[Link]()
[Link] will be the output of the following code? import [Link] as p
x = [6, 7, 8, 9, 10]
y = [60, 40, 55, 30, 70]
[Link]('Secondary Class Strength')
[Link]('Class')
[Link]('No. of students')
[Link](x, y)
[Link]()
Ans:
3. Fill in the blank with appropriate pyplot methods: import
[Link] as p
Year = [2000, 2002, 2004, 2006]
Rate = [21.0, 20.7, 21.2, 21.6]
___________________ # To draw a line graph
[Link]('Year')
[Link]('Rate')
[Link]('Fuel Rates in every Two Year')
__________________(“[Link]”) # To save the
graph [Link]()
Ans. [Link](Year, Rate), [Link]
4. Write a python program to draw a bar chart with the following
information:
City Population
Kolkata 78
Delhi 91
Kanpur 88
Patna 90
Banglore 82
The barchart should have the following features:
a) X-axis label should be City and Y-axis label should be Pollution
b) The title of the chart should be Pollution Index
c) The colour of the bars should be Red
Ans:
import [Link] as plt
import numpy as np
city = [Link](['Kolkata', 'Delhi', 'Kanpur',
'Patna', 'Bangalore'])
pollution = [Link]([78, 91, 88, 90, 82])
[Link]('City')
[Link]('Pollution')
[Link]('Pollution Index')
[Link](city, pollution, color = 'red')
[Link]()
5. Write a python program to draw a histogram with following information:
10, 15, 10, 10, 10, 15, 20, 20, 20, 20,
20, 25, 25 The histogram should have
following information
a) X-axis label should be score and Y-axis should be Frequency
b) The title should be Frequency of Score
c) The colour of histogram should be blue with 10 bins
d) Ans: import [Link] as plt
import numpy as np
arr = [Link]([10, 15, 10, 10, 10, 15, 20, 20, 20,
20, 20, 25, 25])
[Link]('Score')
[Link]('Frequency')
[Link]('Frequency of Score')
[Link](arr, color = 'blue', bins = 10)
[Link]()