CBSE Class 12
Informatics Practices
04 Plotting Data using Matplotlib
40
Total
0
Attempted
0
Correct
0
Wrong
00:00:00
Q-1
Which type of plot is most suitable to represent the change in temperature over days?
Easy
Matplotlib Basics
Sample Data
| Day | Temperature |
|---|---|
| Mon | 28 |
| Tue | 30 |
| Wed | 31 |
| Thu | 29 |
A
Bar chart
B
Pie chart
C
Line graph
D
Histogram
Answer: Line graph
Explanation: A line graph is best suited for showing changes or trends over time.
Q-2
Which library must be imported to create plots using pyplot?
Easy
Matplotlib Basics
A
pandas
B
numpy
C
matplotlib.pyplot
D
scipy
Answer: matplotlib.pyplot
Explanation: The pyplot module of matplotlib is used to create plots.
Q-3
What type of graph will be displayed by the following code?
Easy
Plotting using Matplotlib
Sample Data
| x | y |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 6 |
Reference Code
import matplotlib.pyplot as plt
x = [1,2,3]
y = [2,4,6]
plt.plot(x, y)
plt.show()
A
Bar chart
B
Line graph
C
Scatter plot
D
Histogram
Answer: Line graph
Explanation: The plot() function draws a line graph by default.
Q-4
Which function is used to label the x-axis of a plot?
Easy
Plot Customisation
A
plt.xlabel()
B
plt.ylabel()
C
plt.title()
D
plt.legend()
Answer: plt.xlabel()
Explanation: plt.xlabel() is used to label the x-axis.
Q-5
Which plot is most appropriate to compare marks obtained by students in different subjects?
Easy
Plotting using Matplotlib
Sample Data
| Subject | Marks |
|---|---|
| Maths | 85 |
| Science | 78 |
| English | 90 |
A
Line graph
B
Histogram
C
Bar chart
D
Pie chart
Answer: Bar chart
Explanation: Bar charts are suitable for comparing values across different categories.
Q-6
What is the purpose of the following statement in a plotting program?
Easy
Plot Customisation
Reference Code
plt.title('Monthly Sales')
A
Labels the x-axis
B
Labels the y-axis
C
Adds a title to the plot
D
Displays the legend
Answer: Adds a title to the plot
Explanation: plt.title() adds a descriptive title to the plot.
Q-7
Which type of plot will be generated by the following code?
Easy
Plotting using Matplotlib
Sample Data
| Value |
|---|
| 10 |
| 20 |
| 20 |
| 30 |
Reference Code
plt.hist([10,20,20,30])
plt.show()
A
Bar chart
B
Histogram
C
Line graph
D
Scatter plot
Answer: Histogram
Explanation: hist() generates a histogram to show frequency distribution of values.
Q-8
Which statement is correct about plt.show()?
Easy
Matplotlib Basics
A
It saves the plot as an image file
B
It displays the plot window
C
It clears the current plot
D
It labels the axes
Answer: It displays the plot window
Explanation: plt.show() displays the plotted graph on the screen.
Q-9
Which function is used to display a legend for plotted data?
Easy
Plot Customisation
A
plt.text()
B
plt.legend()
C
plt.grid()
D
plt.annotate()
Answer: plt.legend()
Explanation: plt.legend() displays labels for different plot elements.
Q-10
Which Pandas feature allows direct plotting of DataFrame columns?
Easy
Pandas Plot Function
A
df.graph()
B
df.draw()
C
df.plot()
D
df.visualize()
Answer: df.plot()
Explanation: The plot() method of a Pandas DataFrame allows direct plotting of data.
Q-11
Which plot type is most appropriate to compare the distribution of marks?
Medium
Plotting using Matplotlib
Sample Data
| Marks |
|---|
| 35 |
| 40 |
| 45 |
| 60 |
| 75 |
A
Line graph
B
Histogram
C
Pie chart
D
Bar chart
Answer: Histogram
Explanation: A histogram shows the frequency distribution of numerical data.
Q-12
What will be the visual effect of the following code?
Medium
Plot Customisation
Sample Data
| x | y |
|---|---|
| 1 | 5 |
| 2 | 10 |
| 3 | 15 |
Reference Code
plt.plot(x, y, marker='o')
plt.show()
A
Only points without lines
B
Line with circular markers at data points
C
Bar chart with markers
D
Scatter plot without lines
Answer: Line with circular markers at data points
Explanation: marker='o' adds circular markers while retaining the line plot.
Q-13
Which change will display grid lines on the graph?
Medium
Plot Customisation
A
plt.legend()
B
plt.grid()
C
plt.axis()
D
plt.show()
Answer: plt.grid()
Explanation: plt.grid() enables grid lines on the plot.
Q-14
What is the effect of the following code?
Medium
Plotting using Matplotlib
Sample Data
| Year | Sales |
|---|---|
| 2021 | 100 |
| 2022 | 150 |
| 2023 | 200 |
Reference Code
plt.bar(Year, Sales)
plt.xlabel('Year')
plt.ylabel('Sales')
A
Displays a line graph
B
Displays a bar chart with labeled axes
C
Displays a histogram
D
Displays a pie chart
Answer: Displays a bar chart with labeled axes
Explanation: bar() creates a bar chart, and xlabel()/ylabel() label the axes.
Q-15
Which plot will best represent the contribution of each subject to total marks?
Medium
Plotting using Matplotlib
Sample Data
| Subject | Marks |
|---|---|
| Maths | 80 |
| Science | 70 |
| English | 50 |
A
Line graph
B
Histogram
C
Pie chart
D
Scatter plot
Answer: Pie chart
Explanation: Pie charts are suitable for showing part-to-whole relationships.
Q-16
Which statement correctly describes the following code?
Medium
Plot Customisation
Sample Data
| x | y1 | y2 |
|---|---|---|
| 1 | 2 | 3 |
| 2 | 4 | 6 |
Reference Code
plt.plot(x, y1, label='A')
plt.plot(x, y2, label='B')
plt.legend()
A
Plots two lines without labels
B
Plots two lines with a legend
C
Plots a scatter plot
D
Plots a bar chart
Answer: Plots two lines with a legend
Explanation: label combined with plt.legend() displays a legend for multiple lines.
Q-17
What happens if plt.show() is not used in a script?
Medium
Matplotlib Basics
A
Plot is saved automatically
B
Plot may not be displayed
C
Plot is deleted
D
Program gives an error
Answer: Plot may not be displayed
Explanation: Without plt.show(), the plot may not appear when running a script.
Q-18
Which Pandas statement will generate a line plot by default?
Medium
Pandas Plot Function
Sample Data
| Month | Sales |
|---|---|
| Jan | 120 |
| Feb | 150 |
| Mar | 180 |
A
df.plot(kind='bar')
B
df.plot(kind='pie')
C
df.plot()
D
df.plot(kind='hist')
Answer: df.plot()
Explanation: df.plot() generates a line plot by default.
Q-19
Which plot is best suited to show the relationship between two numerical variables?
Medium
Plotting using Matplotlib
Sample Data
| Height | Weight |
|---|---|
| 150 | 45 |
| 160 | 55 |
| 170 | 65 |
A
Histogram
B
Pie chart
C
Scatter plot
D
Bar chart
Answer: Scatter plot
Explanation: Scatter plots are used to show relationships between two numerical variables.
Q-20
What will be the result of the following Pandas plotting code?
Medium
Pandas Plot Function
Sample Data
| Value |
|---|
| 10 |
| 20 |
| 30 |
Reference Code
df['Value'].plot(kind='hist')
A
Bar chart of values
B
Line graph of values
C
Histogram of values
D
Pie chart of values
Answer: Histogram of values
Explanation: Using kind='hist' generates a histogram from the Series.
Q-21
Which plot will best help identify the presence of outliers in the dataset?
Hard
Plotting using Matplotlib
Sample Data
| Marks |
|---|
| 35 |
| 38 |
| 40 |
| 42 |
| 95 |
A
Line graph
B
Histogram
C
Scatter plot
D
Pie chart
Answer: Histogram
Explanation: A histogram helps reveal skewness and outliers by showing frequency distribution.
Q-22
What will be the visual outcome of the following code?
Hard
Plot Customisation
Sample Data
| x | y |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
Reference Code
plt.plot(x, y, linestyle='--', marker='s')
plt.show()
A
Solid line with circular markers
B
Dashed line with square markers
C
Scatter plot only
D
Bar chart with markers
Answer: Dashed line with square markers
Explanation: linestyle='--' creates a dashed line and marker='s' places square markers.
Q-23
Which conclusion can be drawn from a line plot that is nearly horizontal?
Hard
Plot Interpretation
Sample Data
| Time | Value |
|---|---|
| T1 | 50 |
| T2 | 51 |
| T3 | 50 |
| T4 | 49 |
A
Values are increasing rapidly
B
Values show high variability
C
Values remain almost constant
D
Values are unrelated to time
Answer: Values remain almost constant
Explanation: A nearly horizontal line indicates very little change in values over time.
Q-24
What is the effect of specifying bins=5 in a histogram?
Hard
Plot Customisation
Sample Data
| Values |
|---|
| 10 |
| 20 |
| 30 |
| 40 |
| 50 |
Reference Code
plt.hist(values, bins=5)
A
Creates five separate histograms
B
Divides data range into five intervals
C
Displays five data points only
D
Sorts data into five rows
Answer: Divides data range into five intervals
Explanation: bins defines the number of intervals used to group data in a histogram.
Q-25
Which plotting approach will generate multiple plots in separate panels?
Hard
Pandas Plot Function
Sample Data
| Month | Sales | Profit |
|---|---|---|
| Jan | 100 | 20 |
| Feb | 150 | 30 |
A
plt.plot(Sales, Profit)
B
df.plot()
C
df.plot(subplots=True)
D
plt.subplot()
Answer: df.plot(subplots=True)
Explanation: Using subplots=True creates separate panels for each column.
Q-26
Which plot is MOST appropriate to compare two numerical variables with many data points?
Hard
Plotting using Matplotlib
Sample Data
| Height | Weight |
|---|---|
| 150 | 45 |
| 152 | 47 |
| 160 | 55 |
| 170 | 65 |
A
Line graph
B
Scatter plot
C
Pie chart
D
Histogram
Answer: Scatter plot
Explanation: Scatter plots effectively show relationships between two numerical variables.
Q-27
What will be the effect of the following Pandas plotting code?
Hard
Pandas Plot Function
Sample Data
| A | B |
|---|---|
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
Reference Code
df.plot(kind='bar')
A
Single bar per row
B
Multiple bars per row for each column
C
Histogram of values
D
Line plot of both columns
Answer: Multiple bars per row for each column
Explanation: DataFrame bar plots display grouped bars for each column at every index.
Q-28
Which situation would make a pie chart misleading?
Hard
Plot Interpretation
Sample Data
| Category | Value |
|---|---|
| A | 5 |
| B | 95 |
A
When categories represent proportions
B
When data has only one category
C
When values are extremely imbalanced
D
When values sum to 100
Answer: When values are extremely imbalanced
Explanation: Extreme imbalance can hide meaningful comparison in pie charts.
Q-29
What will be the effect of calling plt.legend() without specifying labels?
Hard
Plot Customisation
A
Legend is displayed with default labels
B
Legend is not displayed
C
Program raises an error
D
Legend displays axis names
Answer: Legend is not displayed
Explanation: Without labels defined in plot calls, plt.legend() has nothing to display.
Q-30
Which inference is CORRECT when two line plots intersect at a point?
Hard
Plot Interpretation
Sample Data
| Time | A | B |
|---|---|---|
| T1 | 10 | 15 |
| T2 | 20 | 20 |
| T3 | 30 | 25 |
A
One variable stops changing
B
Both variables have equal values at that point
C
Both variables have maximum values
D
The plot is incorrect
Answer: Both variables have equal values at that point
Explanation: Intersection indicates both variables have the same value at that point.
Q-31
Which type of graph is most suitable to represent sales trend over years?
Easy
Matplotlib Basics
Sample Data
| Year | Sales |
|---|---|
| 2021 | 120 |
| 2022 | 150 |
| 2023 | 180 |
A
Bar chart
B
Pie chart
C
Line graph
D
Histogram
Answer: Line graph
Explanation: Line graphs are best for showing trends or changes over time.
Q-32
Which function is used to display the plotted graph on the screen?
Easy
Matplotlib Basics
A
plt.draw()
B
plt.plot()
C
plt.show()
D
plt.figure()
Answer: plt.show()
Explanation: plt.show() displays the plotted figure.
Q-33
Which plot is most appropriate to compare marks scored by students in different subjects?
Medium
Plotting using Matplotlib
Sample Data
| Subject | Marks |
|---|---|
| Maths | 85 |
| Science | 78 |
| English | 90 |
A
Line graph
B
Histogram
C
Bar chart
D
Scatter plot
Answer: Bar chart
Explanation: Bar charts are suitable for comparing values across categories.
Q-34
What will be the effect of the following code?
Medium
Plot Customisation
Sample Data
| x | y |
|---|---|
| 1 | 3 |
| 2 | 6 |
| 3 | 9 |
Reference Code
plt.plot(x, y, marker='o')
plt.show()
A
Only points without lines
B
Line plot with circular markers
C
Scatter plot
D
Bar chart
Answer: Line plot with circular markers
Explanation: marker='o' adds circular markers to the line plot.
Q-35
Which statement correctly describes the output of df.plot()?
Medium
Pandas Plot Function
Sample Data
| Month | Sales |
|---|---|
| Jan | 100 |
| Feb | 120 |
| Mar | 150 |
A
Creates a bar chart by default
B
Creates a pie chart by default
C
Creates a line plot by default
D
Creates a histogram by default
Answer: Creates a line plot by default
Explanation: df.plot() generates a line plot by default.
Q-36
Which function should be used to display a legend when multiple lines are plotted?
Medium
Plot Customisation
A
plt.text()
B
plt.grid()
C
plt.legend()
D
plt.axis()
Answer: plt.legend()
Explanation: plt.legend() displays labels for plotted data.
Q-37
Which plot is best suited to study the frequency distribution of numerical data?
Medium
Plotting using Matplotlib
Sample Data
| Values |
|---|
| 10 |
| 20 |
| 20 |
| 30 |
| 40 |
A
Line graph
B
Bar chart
C
Histogram
D
Pie chart
Answer: Histogram
Explanation: Histograms show frequency distribution of numerical data.
Q-38
Which plot will best help in identifying outliers in the data?
Hard
Plot Interpretation
Sample Data
| Marks |
|---|
| 35 |
| 38 |
| 40 |
| 42 |
| 95 |
A
Line graph
B
Pie chart
C
Histogram
D
Bar chart
Answer: Histogram
Explanation: A histogram helps identify outliers by showing data distribution.
Q-39
What does the intersection of two lines in a graph indicate?
Hard
Plot Interpretation
Sample Data
| Time | A | B |
|---|---|---|
| T1 | 10 | 15 |
| T2 | 20 | 20 |
| T3 | 30 | 25 |
A
Both variables are constant
B
Both variables have equal values at that point
C
Both variables reach maximum
D
Graph is incorrect
Answer: Both variables have equal values at that point
Explanation: Intersection indicates both variables have the same value at that point.
Q-40
Which Pandas plotting option will create separate plots for each column?
Hard
Pandas Plot Function
Sample Data
| Month | Sales | Profit |
|---|---|---|
| Jan | 100 | 20 |
| Feb | 150 | 30 |
A
df.plot()
B
df.plot(kind='bar')
C
df.plot(subplots=True)
D
df.plot(kind='hist')
Answer: df.plot(subplots=True)
Explanation: subplots=True creates separate plots for each column.
◀
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
▶