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:
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
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.
Related questions:
2026: 23 May Shift 2
2025: 14 May Shift 1
2025: 27 May Shift 2
2026: 26 May Shift 1