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 |
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
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()
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
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 |
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')
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()
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
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
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
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 |
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()
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
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')
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 |
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()
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
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 |
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 |
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')
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 |
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()
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 |
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)
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 |
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 |
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')
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 |
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
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 |
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 |
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
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 |
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()
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 |
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
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 |
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 |
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 |
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 |
Answer: df.plot(subplots=True)
Explanation: subplots=True creates separate plots for each column.