A. Missing plt.legend() call to display the legend
B. Labels are incorrectly assigned inside plt.plot()
C. plt.show() should be called before plotting
D. series2 should be plotted before series1
Solution
Step 1: Check for legend display code
The code does not call plt.legend(), so labels won't show.
Step 2: Confirm label usage is correct
Labels are correctly passed in plt.plot(), so no issue there.
Final Answer:
Missing plt.legend() call to display the legend -> Option A
Quick Check:
Legend missing without plt.legend() [OK]
Hint: Always add plt.legend() to show labels on plot [OK]
Common Mistakes:
Assuming labels show automatically without legend call
Thinking order of plotting affects legend display
Calling plt.show() too early
5. You have three time series with different lengths: series1 = [1, 2, 3, 4], series2 = [2, 3, 4], series3 = [1, 3, 5, 7, 9]. How can you correctly plot all three on the same graph to compare them over time?
hard
A. Plot all series using the length of the longest series only
B. Plot each series with its own x-axis range matching its length, then add labels and legend
C. Pad shorter series with zeros to match the longest series length before plotting
D. Plot only the shortest series to avoid errors
Solution
Step 1: Understand different lengths require matching x-axis
Each series must be plotted with x values matching its length to avoid misalignment.
Step 2: Plot each series with its own x range and add labels
Use range(len(series)) for x-axis, plot all, then add labels and legend.
Final Answer:
Plot each series with its own x-axis range matching its length, then add labels and legend -> Option B
Quick Check:
Match x-axis length per series + labels = Plot each series with its own x-axis range matching its length, then add labels and legend [OK]
Hint: Use range(len(series)) for x-axis of each series [OK]
Common Mistakes:
Plotting all series without adjusting x-axis causes misaligned lines
Padding with zeros changes data meaning
Ignoring series length differences
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.