Chapter-3 Plotting Data using Matplotlib — Online MCQ Test
INFORMATICS PRACTICES · Grade 12 · CBSE(NCERT)
Practice Chapter-3 Plotting Data using Matplotlib with a free chapter-wise online MCQ test.
This chapter covers: Matplotlib - Pyplot - line chart - bar graph - histogram - labels - scales - titles - legends.
AI-generated questions from basic to board-exam level, with instant results and explanations.
Chapter-3 Plotting Data using Matplotlib — Important Questions & Answers
Which module in Python is primarily used for data visualization and plotting?
- A. NumPy
- B. Matplotlib
- C. Pandas
- D. SciPy
Answer: B. Matplotlib
Matplotlib is the primary Python library for creating static, animated, and interactive visualizations including charts and graphs.
Matplotlib is the primary Python library for creating static, animated, and interactive visualizations including charts and graphs.
What does 'pyplot' refer to in matplotlib?
- A. A data structure for storing plot data
- B. A state-based interface for matplotlib
- C. A function to export plots to PDF
- D. A library for statistical analysis
Answer: B. A state-based interface for matplotlib
pyplot (matplotlib.pyplot) is a module that provides a MATLAB-like state-based interface for matplotlib, making it easy to create plots.
pyplot (matplotlib.pyplot) is a module that provides a MATLAB-like state-based interface for matplotlib, making it easy to create plots.
Which command is used to display a plot in matplotlib?
- A. plt.display()
- B. plt.show()
- C. plt.render()
- D. plt.open()
Answer: B. plt.show()
plt.show() is the correct command to display the plot window and render all plotting commands executed previously.
plt.show() is the correct command to display the plot window and render all plotting commands executed previously.
What type of chart is best suited to show trends over time?
- A. Pie chart
- B. Line chart
- C. Histogram
- D. Scatter plot
Answer: B. Line chart
A line chart is ideal for displaying trends over time as it connects data points with lines, showing how values change continuously.
A line chart is ideal for displaying trends over time as it connects data points with lines, showing how values change continuously.
What does plt.xticks() function do?
- A. Creates tick marks on the y-axis
- B. Sets or gets the tick locations on the x-axis
- C. Rotates the x-axis label
- D. Adds a legend to the plot
Answer: B. Sets or gets the tick locations on the x-axis
plt.xticks() is used to get or set the locations and labels of the tick marks on the x-axis for better readability.
plt.xticks() is used to get or set the locations and labels of the tick marks on the x-axis for better readability.
A student wants to display multiple lines on the same plot. Which approach is correct?
- A. Call plt.plot() multiple times before plt.show()
- B. Call plt.show() between each plt.plot() call
- C. Use separate plt.figure() for each line
- D. Use only one plt.plot() with all data
Answer: A. Call plt.plot() multiple times before plt.show()
Multiple plt.plot() commands can be called sequentially before plt.show(), and all lines will be displayed on the same plot.
Multiple plt.plot() commands can be called sequentially before plt.show(), and all lines will be displayed on the same plot.
What does plt.figsize=(10,6) do when creating a figure?
- A. Sets the number of subplots
- B. Sets the width and height of the figure in inches
- C. Sets the resolution of the plot
- D. Sets the font size of labels
Answer: B. Sets the width and height of the figure in inches
plt.figsize=(10,6) specifies the figure dimensions as width=10 inches and height=6 inches, allowing customization of plot size.
plt.figsize=(10,6) specifies the figure dimensions as width=10 inches and height=6 inches, allowing customization of plot size.
When plotting data for temperature changes across 12 months, which would be most appropriate to show the yearly trend?
- A. A pie chart with monthly percentages
- B. A histogram with temperature frequencies
- C. A line chart with months on x-axis and temperature on y-axis
- D. A scatter plot with random distribution
Answer: C. A line chart with months on x-axis and temperature on y-axis
A line chart effectively shows temperature trends across months, displaying seasonal patterns and overall yearly changes clearly.
A line chart effectively shows temperature trends across months, displaying seasonal patterns and overall yearly changes clearly.
Which statement is true about the linestyle parameter in plt.plot()?
- A. It can only be set to 'solid'
- B. It controls the thickness of the line only
- C. It can be set to values like '-', '--', '-.', ':' for different line styles
- D. It is mandatory and must be specified in every plot
Answer: C. It can be set to values like '-', '--', '-.', ':' for different line styles
The linestyle parameter allows customization with '-' (solid), '--' (dashed), '-.' (dash-dot), and ':' (dotted) patterns.
The linestyle parameter allows customization with '-' (solid), '--' (dashed), '-.' (dash-dot), and ':' (dotted) patterns.
When using plt.xticks() with plt.bar(), what is the correct way to align category labels with bar positions in a bar graph?
- A. plt.xticks() automatically aligns labels regardless of data
- B. Use plt.xticks(range(len(categories)), categories) to ensure proper alignment
- C. Labels cannot be properly aligned with plt.xticks()
- D. Use plt.xlabel() instead of plt.xticks()
Answer: B. Use plt.xticks(range(len(categories)), categories) to ensure proper alignment
Using plt.xticks(range(len(categories)), categories) ensures that tick positions correspond to bar positions, preventing label misalignment.
Using plt.xticks(range(len(categories)), categories) ensures that tick positions correspond to bar positions, preventing label misalignment.