Arrange the following in the proper sequence (assume that matplotlib.pyplot is imported as plt):
(A) plt.plot(date, list)
(B) list= [8.5, 0.5, 6.8]
(C) date = ["15/12", "16/12", "17/12"]
(D) plt.show()
Arrange the following in the proper sequence (assume that matplotlib.pyplot is imported as plt):
(A) plt.plot(date, list)
(B) list= [8.5, 0.5, 6.8]
(C) date = ["15/12", "16/12", "17/12"]
(D) plt.show()
Solution
Both lists must exist before they are plotted, and plt.show() must come last because it displays whatever has already been plotted.
(B) list= [8.5, 0.5, 6.8] creates the y-values.
(C) date = ["15/12", "16/12", "17/12"] creates the x-values.
(A) plt.plot(date, list) draws the graph using both lists.
(D) plt.show() displays the finished plot.
Options 2 and 3: plt.plot(date, list) is called before date is defined (Option 2 also before list), which gives a NameError.
Option 4: plt.show() runs before plt.plot(...), so nothing is plotted when the window appears.
Related questions:
2025: 21 May Shift 1
2025: 22 May Shift 1
2025: 22 May Shift 1
2026: 18 May Shift 2
2025: 16 May Shift 1