Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib plotting library.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole matplotlib instead of pyplot.
Using numpy or pandas instead of matplotlib.pyplot.
✗ Incorrect
We use matplotlib.pyplot to create plots in Python.
2fill in blank
mediumComplete the code to plot the first time series data.
Matplotlib
plt.plot(time, [1], label='Series 1')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable like
series2.Using
time for both x and y.✗ Incorrect
The first series data is stored in the variable series1.
3fill in blank
hardFix the error in the code to add a legend to the plot.
Matplotlib
plt.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
legends() which does not exist.Trying to use
label() instead of legend().✗ Incorrect
The correct function to show the legend is plt.legend().
4fill in blank
hardFill both blanks to plot the second series with a red dashed line and add a title.
Matplotlib
plt.plot(time, series2, color='r', [1]='--') plt.[2]('Comparison of Two Series')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
color instead of linestyle.Using
xlabel instead of title.✗ Incorrect
Use color='r', linestyle='--' to make a red dashed line and plt.title() to add a title.
5fill in blank
hardFill all three blanks to create a complete plot with labels, legend, and show it.
Matplotlib
plt.plot(time, series1, label=[1]) plt.plot(time, series2, label=[2]) plt.legend() plt.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around label names.
Using
plt.legend without parentheses.Not calling
plt.show() to display the plot.✗ Incorrect
Labels are strings for the legend. Use plt.legend() to show the legend and plt.show() to display the plot.