0
0
Matplotlibdata~10 mins

Multiple time series comparison in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the matplotlib plotting library.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Amatplotlib.pyplot
Bnumpy
Cpandas
Dseaborn
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole matplotlib instead of pyplot.
Using numpy or pandas instead of matplotlib.pyplot.
2fill in blank
medium

Complete 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'
Aseries1
Bseries2
Ctime
Dlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable like series2.
Using time for both x and y.
3fill in blank
hard

Fix 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'
Ashowlegend
Blegends
Clabel
Dlegend
Attempts:
3 left
💡 Hint
Common Mistakes
Using legends() which does not exist.
Trying to use label() instead of legend().
4fill in blank
hard

Fill 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'
Alinestyle
Bcolor
Ctitle
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using color instead of linestyle.
Using xlabel instead of title.
5fill in blank
hard

Fill 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'
A'Series 1'
B'Series 2'
Clegend
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around label names.
Using plt.legend without parentheses.
Not calling plt.show() to display the plot.