arrow
arrow
arrow
Observe the following graph and find the missing statement in the Python code. import matplotlib.pyplot as pl ______ pl.show()
Question

Observe the following graph and find the missing statement in the Python code.
import matplotlib.pyplot as pl
______
pl.show()

A.

pl.bar([5, 2, 3, 1])

B.

pl.scatter([5, 2, 3, 1])

C.

pl.plot([5, 2, 3, 1])

D.

pl.line([5, 2, 3, 1])

Correct option is C


To plot the data as a line plot, the appropriate function in Matplotlib is pl.plot(). This function is used to plot continuous data points connected by lines, as seen in the graph you provided.
Code Explanation:
The correct code will be:
import matplotlib.pyplot as pl
pl.plot([5, 2, 3, 1])
pl.show()
Important Key Points:
1. pl.plot(): This function is used to plot a line graph, which connects data points with a continuous line.
2. pl.show(): This displays the plot to the screen.
3. Line Plot: In the given graph, the points are connected by a line, making pl.plot() the correct function to use.
Knowledge Booster:
· Option (a): pl.bar([5, 2, 3, 1]) would create a bar graph, not a line graph. It does not match the structure of the given graph.
· Option (b): pl.scatter([5, 2, 3, 1]) would create a scatter plot, where individual points are plotted without connecting lines. This is not what is shown in the given graph.
· Option (d): pl.line([5, 2, 3, 1]) is not a valid function in Matplotlib. The correct function to create a line plot is pl.plot().

Free Tests

Free
Must Attempt

DSSSB PRT Full Mock - 01

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

Educational Psychology & Pedagogy - 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon15 Mins
languageIcon English
Free
Must Attempt

DSSSB PRT PYP Held on 7th March 2022 Shift 1

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
368k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow