Plotting with pyplot Assignments Class-12 is one of the topics of the CBSE curriculum, subject – Informatics Practices code 065. In this article, you will get the assignments for the same.
Topics Covered
Objective type questions (Plotting with pyplot Assignments Class-12)
MCQs, Fill in the blanks and True/False
Q – 1 A _________ refers to the graphical representation of data and information using charts or diagrams or maps.
–> Data Visualization
Q – 2 Data visualization helps to
a) Understand data easily
b) Take a decisions
c) Improve the past performance
d) All of these
Q – 3 The ______ module allows you to represent data visually in various forms.
–> pyplot
Q – 4 The ________ library provides the interface and functionality for plotting the graphs.
–> matplotlib
Q – 5 Which of the following offers many different names collections of methods?
a) PyPlot
b) matplotlib
c) matlab
d) graphs
Q -6 Which of the following correct statement to import pyplot module?
a) import matplotlib.pyplot
b) import MatPlotLib.PyPlot
c) import PyPlot as pl
d) import pyplot.plot
Q – 7 A __________ chart displays information as a markers connected by a straight lines.
–> Line
Q – 8 A bar chart is also known as column chart. (True/False)
Q – 9 The entire is covered by the graph is known as __________
–> Figure or Chart Area
Q – 10 Which is a common method used to plot data on the chart?
a) plot()
b) show()
c) legend()
d) title()
Q – 11 Which of the following is/are correct statement for plot method?
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
Q – 13 To give a title to x-axis, which of the following method is useful?
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)
Q – 15 The _________ method is used to create a line chart.
a) pl.pie()
b) pl.col()
c) pl.plot()
d) pl.line()
Q – 16 To create a horizontal bar chart, bar() function is used. (True/False)
Q – 17 To change the width of bars in bar chart, which of the following argument with a float value is used?
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)
Q – 20 Which method is used to display or show the legends?
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?
The data visualization technique refers to the graphical or pictorial or visual representation of data. This can be achieved by charts, graphs, diagrams, or maps.
Q – 2 How data visualization can help in decision making?
Most data visualization technique provides data in form of charts or graphs. These charts are majorly used in producing various reports like trends, outliers, and other diagrams. By observing these all users can understand the data easily and he/she can take their decision.
Q – 3 Name the library and interface used to plot a chart in python.
Library – matplotlib
interface – pyplot
Q – 4 What are the ways of importing matplotlib?
You can import matplotlib in following two ways:
- Using alias name: import matplotlib.pyplot as pp
- Without alias name: import matplotlib.pyplot
Q -5 What are the basic elements/components of the chart?
The chart has following elements/components:
- Chart area or figure
- Axis
- Artist
- Titles
- Legends
Q -6 Write steps to plot your data on a graph.
- import module i.e import matplolib.pyplot as pp
- Choose the desired chart type to plot data. For ex. Line chart
- Use proper titles for axis
- Add data points
- Add more properties to the graph like color, size etc.
Q – 7 What types of graphs can be plotted using matplotlib?
The matplotlib provides following types of charts:
- Line chart
- Bar chart
- Horizontal bar chart
- Histogram
- Scatter chart
- Boxplot
- Pie Chart
The below given questions from Plotting with pyplot Assignments are based on applications.
Q – 8 Write code to do the following:
[1] Plot the following data on line chart:
Runs in Overs | 10 | 20 |
MI | 110 | 224 |
RCB | 85 | 210 |
import matplotlib.pyplot as mpp
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()
Q – 9 How to change the thickness of line, line style, line color, and marker properties of a chart?
To change the thickness of line, use the linewidth parameter inside matplotlib.pyplot.plot() function with a numeric value. For ex.: pp.plot(x,y,linewidth=2)
To change the line style, use linestyle or ls parameter. This linestyle can be one of the following:
- solid
- dashed
- dashdot
- 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.
To change the markers user marker properties as following:
[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’)
[2] markersize: It can be a numeric value.
Ex. pp.plot(x,y,marker=’D’,markersize=4)
[3] markeredgecolor: It can be a color shortcode or color name or color code.
Ex. pp.plot(x,y,marker=’D’,markeredgecolor=’blue’)
Q – 10 Plot following data on bar graph:
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()
Click here to read notes on Data Visualization using pyplot.
CBSE has introduced competency-based questions. In the next section of Plotting with pyplot Assignments, I am going to cover some competency-based on Plotting with pyplot Assignments.
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.
import ________________ as plt #Statement 1
apps=["Arogya Setu","WPS Office","Cam Scanner","WhatsApp","Telegram"]
ps_rating=[3.9,4.5,4.6,4.2,4.3]
plt.__________(apps,ps_rating,color='m',label=__________) #Statement 2 Statement 3
plt.xlabel("Apps")
plt._____________("Rating") #Statement 4
plt._________ #Statement 5
plt.________ #Statement 6
i) Write the appropriate statement for #statement 1 to import the module.
ii) Write the function name and label name as displayed in the output for #statement 2 and #statement 3 respectively.
iii) Which word should be used for #statement 4?
iv) Write appropriate method names for #Statement 5 to display legends and #Statement 6 to open the figure.
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
ii) bar, App Rating
iii) ylabel
iv) legend(), show()
v) Statement 2 should be changed. It requires plot() method to plot the data.
[2] Mrs. Namrata is a coordinator in the senior section school. She represented data on number of students who passed the exam on line chart as follows:
She has written the following code but not getting the desired output. Help her by correcting her code.
import matplotlib.pyplot as plt
classes=["X A","X B","XI A","XI B","XII A","XII B"]
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.xtitle("No of Stduents") #Statement 3
plt.ytitle("Classes") #Statement 4
plt.show()
i) What will be the correct code for Statement 1 and Statement 2?
ii) What is the correct function name for Statement 3 and Statement 4?
iii) Write a method and parameter required to display legends?
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.
vi) How to apply the line colours as given in the figure?
vii) Write to save the figure as image.
Ans.:
i) The code for statement 1 and statement 2 is as follows:
- Statement 1: plt.plot(classes,no_of_boys)
- Statement 2:plt.plot(classes,no_of_girls)
ii) The correct code for statement 3 and statement 4 is as follows:
- plt.xlabel(‘classes’)
- plt.ylabel(‘No of stduents’)
iii) To display the legend she need to add label parameter in the plot method as following:
- plt.plot(classes,no_of_boys,label=’Boys’)
- plt.plot(classes,no_of_girls,label=’Girls’)
To display legend she need to write this function:
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')
vi) She can use color parameter to apply colours as follows:
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]
(i) Consider the following statements with reference to Line charts:
a) Line chart is a tool for comparison and is created by plotting a series of several points connecting them with a straight line.
b) You should never use a line chart when the chart is in a continuous data set.
Which of the above statement(s) are true?
(ii) Consider the following statements with reference to data visualization:
a) Graphical representation of information and data
b) Helps users in analyzing a large amount of data in a simpler way
c) Data visualization makes complex data more accessible, understandable and usable
d) No library needs to be imported to use charts in python
Which of the statement(s) are not true?
(iii) Consider these statements:
a) The figure() attribute is used to save the plot created by python
b) The filename for saving the plot must be written with a complete path including an extension
Which the following statement(s) are true?
Ans.:
(i) a) is correct , b) is incorrect
(ii) d) No library needs to be imported to use charts in python
(iii) a) and b) both are incorrect
I hope these questions will help you with your exams. If you have any doubts or queries related to this topic feel free to ask in the comment section.
Thank you for reading this article.