Sunday, 16 May 2021

Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1 (#class12InformaticsPractices)(#Matplotlib)(#PythonVisualisation)(#eduvictors)

Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1

Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1 (#class12InformaticsPractices)(#Matplotlib)(#PythonVisualisation)(#eduvictors)



Q1: Define visualisation.

Answer: Data visualisation means graphical or pictorial representation of the data using graph, chart, maps etc. 


Q2: Name any library that is used for data visualisation in Python.

Answer: matplotlib is a python library that provides various types of data visualisation interfaces.


Q3: How does visualisation help?

Answer: Visualisation also helps to effectively communicate information to intended users.



Q4: Name sectors where data visualisation is effectively used.

Answer: Visualisation of data is effectively used in fields like health, finance, science, mathematics, engineering, etc.


Q6: What is pyplot? How is used in python program?

Answer: Pyplot is a collection of methods within matplotlib library that allows use to construct 2D plots and graphs easily and interactively.


Command used to call pyplot is:


>>> import matplotlib.pyplot as plt


Q7: Name the command to install matplotlib

Answer:  pip install matplotlib


Q8: The following table lists the last week Delhi's maximum Temperature. Plot a line graph showing Temperature against date.

Date   - Temperature (°C)

3/5/21 - 39

4/5/21 - 41

5/5/21 - 40

6/5/21 - 39

7/5/21 - 35

8/5/21 - 38

9/5/21 - 39


Answer

import matplotlib.pyplot as plt

date=["3/5/21","4/5/21","5/5/21","6/5/21","7/5/21", "8/5/21", "9/5/21"]

temp=[39,41,40,39,35,38,39]

plt.plot(date, temp)

plt.show()


Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1 (#class12InformaticsPractices)(#Matplotlib)(#PythonVisualisation)(#eduvictors)



Q9: Modify the above program (Q8) with following changes:

(a) Set title as "May Week 2 Delhi Temperature"

(b) Set label for x-axis as "Date"

(c) Set label for y-axis as "Temperature"

(d) Show grids in the background

(e) Set marker as '*'


Answer


import matplotlib.pyplot as plt

date=["3/5/21","4/5/21","5/5/21","6/5/21","7/5/21", "8/5/21", "9/5/21"]

temp=[39,41,40,39,35,38,39]

plt.xlabel("Date")

plt.ylabel("Temperature")

plt.title("May Week 2 Delhi Temperature")

plt.grid(True)

plt.plot(date, temp, marker='*')

plt.show()


Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1 (#class12InformaticsPractices)(#Matplotlib)(#PythonVisualisation)(#eduvictors)



Q10: What is the default line width?


Answer: 1 pixel (thin line)



Q11: Write a python program to show sine chart with line colour as red, line width as "4 pixels" and dashed line style.

Answer


import matplotlib.pyplot as plt

import numpy as np 

xdata = np.arange(0., 10, 0.1)

ydata = np.sin(xdata) 

plt.plot(xdata, ydata, linewidth = 4, linestyle='dashed', color='red')

plt.show()


Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1 (#class12InformaticsPractices)(#Matplotlib)(#PythonVisualisation)(#eduvictors)



Q12: Name the function which is used to save the plot.


Answer: savefig(<filename>)



Q13: What is the purpose of a legend?

Answer: The legend of a graph reflects the data displayed in the graph's Y-axis, also called the graph series. The legend box contains small samples of each colour on the graph as well as a short description of what each colour means.



Q14: What is the purpose of title in a plot?

Answer: Title is the text that appears on the top of the plot. It defines what the chart is about.


Q15: Is it possible to show multiple plots in the same visualisation? Show with an example.

Answer: Yes multiline plots can be shown. Here follows the python snippet.


import matplotlib.pyplot as plt

import numpy as np

x = np.arange(10)

plt.plot(x, x**2)

plt.plot(x, x**3)

plt.plot(x, x*20)

plt.show()


Class 12 Informatics Practices - Plotting Data using Matplotlib ( Questions and Answers) Part-1 (#class12InformaticsPractices)(#Matplotlib)(#PythonVisualisation)(#eduvictors)


👉See Also:

Python - A Quick Revision (Q & A)
Python Snippets (Set-1) 
Python Pandas (Q & A) Part-1
Python Pandas (Q & A) Part-2

Informatics Practices Sample Question Paper with Marking Scheme (2020-21)
Informatics Practices Sample Question Paper (Set-2) 2020-21
Querying and SQL Functions (Worksheet)
Important Abbreviations To Memorise
Networking (Q & A)
Networking - Data Transmission Media (Q & A)
Database Concepts (Important Terms)

 

No comments:

Post a Comment

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.