Chapter 2 - Data Visualization Using Matplotlib - Solutions of Informatics Practices (065) by Preeti Arora For Class 12 CBSE - KnowledgeBoat
Chapter 2 - Data Visualization Using Matplotlib - Solutions of Informatics Practices (065) by Preeti Arora For Class 12 CBSE - KnowledgeBoat
OPEN IN APP
Home / Class 12 - Informatics Practices Preeti Arora / Data Visualization using Matplotlib
Chapter 2
Data Visualization using
Matplotlib
Class 12 - Informatics Practices Preeti Arora
Question 1
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
Pyplot module's hist() let us create histograms.
Question 8
Question 9
Question 10
Question 11
Question 12
Question 13
Question 1
Answer
False
Question 2
Answer
False
Question 3
Answer
True
Question 4
Answer
True
Question 5
Answer
True
Question 6
Answer
False
Question 7
Answer
False
Question 8
To add a title to the plot, we have to call function
header().
Answer
False
Question 9
Answer
True
Question 10
Answer
True
Question 11
Answer
False
Reason — When we don't specify X or Y limits
for a plot, pyplot automatically decides the limits
based on the values being plotted. It sets the
limits to the minimum and maximum values of the
data, so that all the data points are visible in the
plot.
Multiple Choice Questions
Question 1
1. matplotlib.pyplot
2. matplotlib.pip
3. matplotlib.numpy
4. matplotlib.plt
Answer
matplotlib.pyplot
Question 2
1. pip
2. matinfolib
3. matplotlib
4. matpiplib
Answer
matplotlib
1. table
2. charts
3. maps
4. infographics
Answer
charts
Question 4
1. Line plot
2. Histogram
3. Bar plot
4. Table plot
Answer
Table plot
Question 5
Answer
module.
Question 6
1. show()
2. display()
3. execute()
4. plot()
Answer
show()
Question 7
Answer
Question 8
1. legends
2. title
3. axes
4. figure
Answer
legends
Question 9
1. plt.savefig("bar1.pdf" )
2. plt.savefig("bar1.png")
3. plt.savefig("bar1.eps")
4. plt.savefig("bar1.ppt")
Answer
plt.savefig("bar1.ppt")
Question 10
1. Box plot
2. Histogram
3. Line Chart
4. Bar chart
Answer
Line Chart
Question 11
1. plt.show()
2. plt.plot("No. of Patients")
3. plt.xlabel("No. of Patients")
4. plt.title("No. of Patients")
Answer
plt.xlabel("No. of Patients")
Question 12
1. line plot
2. bar graph
3. histogram
4. boxplot
Answer
bar graph
Question 1
Answer
Explanation
Data visualization refers to the graphical or visual
representation of information and data using
visual elements like charts, graphs, and maps.
These visual tools help in analyzing a large
amount of data in a simple way. Because of this,
data visualization makes complex data more
accessible, understandable, and usable.
Question 2
Answer
Explanation
The command to import pyplot is import
matplotlib.pyplot as plt. Matplotlib is a Python 2D
plotting library for creating publication-quality
figures. Pyplot is a module within the Matplotlib
library that contains a collection of methods
which allow users to create 2D plots and graphs
easily and interactively.
Question 3
Answer
Explanation
Data visualization refers to the graphical or visual
representation of information and data using
visual elements like charts, graphs, and maps. To
install the Matplotlib library, we use the command
pip install matplotlib .
Question 4
Answer
Explanation
A histogram is used to represent data provided in
the form of discrete or continuous ranges. The
matplotlib.pyplot.hist() function is used to
Question 5
Answer
Explanation
The statement legend(labels=['Text']) is used
to add a legend to the graph, not a title. The title
of the graph is set using plt.title('Title
Text') . The statement plt.savefig("path")
Question 6
Answer
Question 7
Answer
Explanation
Bar charts and histograms are not the same. A
bar chart or bar graph is a chart that presents
categorical data with rectangular bars, where the
heights or lengths of the bars are proportional to
the values they represent. On the other hand, a
histogram is a type of graph that provides a
visual interpretation of numerical data by
indicating the number of data points that lie within
a range of values, and this corresponds to a
vertical bar.
Question 8
Answer
Explanation
A marker in a chart or graph can have various
elements such as style (e.g., circle, square,
triangle), color, size, and others. The marker
property is used to customize the markers
(points) in a chart, not the line itself. The line in a
line chart can be customized using other
properties such as linestyle, linewidth, color, etc.
Case/Source Based Questions
Question 1
Answer
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("C:\\company_sales_data.csv")
profitList = df['total_profit'].tolist()
monthList = df['month_number'].tolist()
plt.plot(monthList, profitList, label = 'Month
plt.xlabel('Month number')
plt.ylabel("Profit in dollars")
plt.xticks(monthList)
plt.title('Company profit per month')
plt.yticks([100000, 200000, 300000, 400000, 50
plt.show()
Output
Question 2
1. Statement 8
2. Statement 4
3. Statement 1
4. None of these
(ii) Statements 5 & 6 are used to give names to
X-axis and Y-axis as shown in Fig.1. Which of the
following can fill those two gaps?
1.
plt.xlabel('X - axis')
plt.ylabel('Y - axis')
2.
plt.xtitle('x - axis')
plt.ytitle('y - axis')
3.
plt.xlable('x - axis')
pit.ylable('x - axis')
4.
plt.xlabel('x axis')
plt.ylabel('y axis')
1. plt.display()
2. plt.show()
3. matplotlib.pyplot.display()
4. Both (b) & (c)
1. Zero
2. Three
3. Infinite
4. Not defined
1. legend()
2. label()
3. title()
4. Both (a) & (c)
Answer
(i) Statement 4
(ii)
plt.xlabel('X - axis')
plt.ylabel('Y - axis')
(iii) plt.show()
Reason — The plt.show() statement is used to
display the graph.
(iv) Three
(v) title()
Question 1
Answer
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4, 5], ['1M', '2M', '3M',
plt.title("My Title")
plt.xlabel("Year")
plt.ylabel("Population")
plt.xticks([1, 2, 3, 4, 5], ["2019", "2020", "
plt.yticks([1, 2, 3, 4, 5], ['1M', '2M', '3M',
plt.show()
Output
Question 2
What is Matplotlib?
Answer
Question 3
Answer
Question 4
Answer
1. Line plots
2. Scatter plots
3. Bar charts
4. Histograms
5. Pie charts
6. Box plots
Question 5
Answer
Question 6
Answer
Figure Axes
Question 7
Answer
Question 8
Answer
Output
Question 9
Answer
Output
Question 10
Answer
Output
Question 11
Sample data:
Answer
Output
Question 12
Sample data:
Answer
Output
Question 13
Answer
Output
Question 14
Answer
x = np.arange(1, 5)
y = x ** 2
plt.plot(x, y)
plt.show()
Output
Question 15
Answer
Question 16
(a) show()
(b) legend()
Answer
Question 17
Plot a histogram of a class test of 40 students
based on random sets of marks obtained by the
students (MM=100).
Answer
Output
Question 18
Answer
Question 19
Answer
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame(data)
df.to_csv('du_colleges.csv', index=False)
df = pd.read_csv("du_colleges.csv")
plt.bar(df["Stream"], df["Number of Courses"])
plt.xlabel("Stream")
plt.ylabel("Number of Courses")
plt.title("Number of Courses in Each Stream")
plt.show()
Output
Question 20
Answer
Question 21
Answer
The hist() function in Matplotlib's Pyplot
module allows creating various types of
histograms. These include the default bar
histogram (histtype='bar'), step histogram
(histtype='step'), stepfilled histogram
(histtype='stepfilled'), barstacked histogram
(histtype='barstacked').
Question 22
Answer
Question 23(i)
Answer
Output
Question 23(ii)
Answer
Output
Question 23(iii)
Answer
Output
Question 23(iv)
Answer
Output
Question 24
Answer
STUDYLIST