Skip to main contentSkip to solution

Arrange the following code to plot temperature against date using matplotlib in correct order.

A. date = ["25/12", "26/12", "27/12"]

B. temp = [8.5, 10.5, 6.8]

C. plt.plot(date, temp)

D. plt.show()

Choose the correct answer from the options givenbelow:

Solution

✅ Correct Option: 1

A. date = ["25/12", "26/12", "27/12"] creates the x-axis data.

B. temp = [8.5, 10.5, 6.8] creates the y-axis data.

C. plt.plot(date, temp) draws the line, and it needs both lists to exist already.

D. plt.show() displays the figure, so it must come last.


Options 2, 3 and 4: plt.plot(date, temp) run before date and temp are defined gives a NameError, and plt.show() called before plt.plot() displays an empty plot.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question