Consider the following import command: import matplotlib.pyplot as PLT Which…

2023

Consider the following import command: import matplotlib.pyplot as PLT Which of the following command will help us to draw a line chart for given values ?

  1. A.

    PLT.plotline([100, 400, 200, 300]) / PLT.lineplot([100, 400, 200, 300])

  2. B.

    PLT.lineplot([100, 400, 200, 300]) / PLT.plotline([100, 400, 200, 300])

  3. C.

    PLT.line([100, 400, 200, 300]) / PLT.line([100, 400, 200, 300])

  4. D.

    PLT.plot([100, 400, 200, 300]) / PLT.plot([100, 400, 200, 300])

Attempted by 845 students.

Show answer & explanation

Correct answer: D

Correct command: PLT.plot([100, 400, 200, 300])

Why this is correct: matplotlib.pyplot provides the plot function to create line charts. Functions named plotline, lineplot, or line are not part of matplotlib.pyplot.

  • Step 1: Call PLT.plot([100, 400, 200, 300]) to create the line using the given y-values.

  • Step 2: Optionally provide x-values as the first argument if you want explicit x coordinates, for example PLT.plot([0,1,2,3], [100,400,200,300]).

  • Step 3: Call PLT.show() to display the plot when running scripts outside interactive environments.

Common mistake: Using names like plotline, lineplot, or line will raise an AttributeError because those functions do not exist in matplotlib.pyplot.

Explore the full course: Bpsc