DATA VISULAIZATION QUESTION ANSWER
DATA VISULAIZATION QUESTION ANSWER
b) Take a decisions
d) All of these
–> pyplot
–> matplotlib
a) PyPlot
b) matplotlib
c) matlab
d) graphs
a) import matplotlib.pyplot
b) import MatPlotLib.PyPlot
c) import PyPlot as pl
d) import pyplot.plot
a) plot()
b) show()
c) legend()
d) title()
a) pl.plot(x,y,color,others)
b) pl.plot(x,y)
c) pl.plot(x,y,color)
d) all of these
Q – 12 What are the mandatory parameters to plot data on chart for plot()
method?
a) x and y
b) color
c) others
d) None of these
a) pl.xtitle(“title”)
b) pl.xlabel(“title”)
c) pl.xheader(“title”)
d) pl.xlabel.show(“title”)
Q – 14 The pl.show() method must be used to display the chart in the end
of the chart specification. (True/False)
a) pl.pie()
b) pl.col()
c) pl.plot()
d) pl.line()
a) thick
b) thickness
c) width
d) barwidth
Q – 18 You can set different width for different bars in bar chart.
(True/False)
Q – 19 To apply color you can only specify the color names. (True/False)
a) pl.show()
b) pl.display()
c) pl.legend()
d) pl.values()
The following section contains short answer questions for Plotting with
pyplot Assignments Class-12.
Descriptive questions (2/3 marks)
– Plotting with pyplot
Assignments
Q – 1 What do you mean by data visualization technique?
Library – matplotlib
interface – pyplot
1. Line chart
2. Bar chart
3. Horizontal bar chart
4. Histogram
5. Scatter chart
6. Boxplot
7. Pie Chart
The below given questions from Plotting with pyplot Assignments are
based on applications.
Runs in Overs 10
MI 110
RCB 85
overs = [10,20]
mi = [110,224]
mpp.plot(overs,mi,'blue')
rcb=[109,210]
mpp.plot(overs,rcb,'red')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.show()
[2] Write code to plot a line chart to depict the run rate of T20 match from
given data:
Overs Runs
5 45
10 79
15 145
20 234
import matplotlib as pp
overs = [5,10,15,20]
runs = [54,79,145,234]
pp.plot(overs,runs)
pp.xlabel('Overs')
pp.ylabel('Runs')
pp.show()
To change the line style, use linestyle or ls parameter. This linestyle can
be one of the following:
1. solid
2. dashed
3. dashdot
4. dotted
Ex. pp.plot(x,y,linestyle=’dashed’)
To change the color use color shortcode like r for red, g for green and so
on. You can also use the complete colornames or hexadecimal color codes
like #000800 in RGB values. Click here to know more about line colors.
[1] markertype: It can be a symbol such as . (dot), ‘D’ for diamond etc.
Click here for more about marker types.
Ex.: pp.plot(x,y,marker=’D’)
Ex. pp.plot(x,y,marker=’D’,markersize=4)
Ex. pp.plot(x,y,marker=’D’,markeredgecolor=’blue’)
English: 56,78,90,34
Science: 65,77,54,32
Maths: 45,67,43,41
import matplotlib.pyplot as pp
eng = [56,78,90,34]
sci = [65,77,54,32]
maths =[45,67,43,41]
pp.bar(eng,sci,maths)
pp.xlabel('Marks')
pp.ylabel('Subjects')
pp.show()
Comptency-based questions
Plotting with pyplot Assignments
[1] Mr. Vijay is working in the mobile app development industry
and he was comparing the given chart on the basis of the rating
of the various apps available on the play store.
He is trying to write a code to plot the graph. Help Mr. Vijay to fill in the
blanks of the code and get the desired output.
ps_rating=[3.9,4.5,4.6,4.2,4.3]
plt.xlabel("Apps")
plt._____________("Rating") #Statement 4
plt._________ #Statement 5
plt.________ #Statement 6
v) Mr. Vijay wants to change the chart type to a line chart. Which
statement should be updated and which method or function is used?
Ans.:
i) matplotlib.pyplot
iii) ylabel
no_of_boys=[23,22,20,26,33,30]
no_of_girls=[17,10,20,12,5,8]
plt.line(classes,no_of_boys) #Statement 1
plt.line(classes,no_of_girls) #Statement 2
plt.ytitle("Classes") #Statement 4
plt.show()
ii) What is the correct function name for Statement 3 and Statement 4?
iv) Name the parameter and values used to apply the marker as given in
the output.
v) Name the parameter and values used to apply linestyle as given in the
output.
Ans.:
1. Statement 1: plt.plot(classes,no_of_boys)
2. Statement 2:plt.plot(classes,no_of_girls)
1. plt.xlabel(‘classes’)
2. plt.ylabel(‘No of stduents’)
iii) To display the legend she need to add label parameter in the plot
method as following:
1. plt.plot(classes,no_of_boys,label=’Boys’)
2. plt.plot(classes,no_of_girls,label=’Girls’)
plt.legend()
iv) To apply the marker as given in the figure she needs to write the code
as follows:
plt.plot(classes,no_of_boys,marker='D')
plt.plot(classes,no_of_girls,marker='o')
v) To apply the lines styles she needs to use a parameter linestyle or ls
with the values ‘dashed’ and ‘dotted’ respectively as follows:
plt.plot(classes,no_of_boys,ls='dashed')
plt.plot(classes,no_of_girls,ls='dotted')
plt.plot(classes,no_of_boys,color='m')
plt.plot(classes,no_of_girls,color='pink')
vii) To save the figure as image she needs to use savefig() method as
follows:
plt.savefig('boygirlspass.jpg')
[3]
b) You should never use a line chart when the chart is in a continuous
data set.
b) The filename for saving the plot must be written with a complete path
including an extension
Ans.: