0
0
Matplotlibdata~10 mins

Downsampling strategies 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 pyplot module with the common alias.

Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Agraph
Bplot
Cmpl
Dpyplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot' causes import errors.
Using 'mpl' or 'graph' are not valid module names.
2fill in blank
medium

Complete the code to plot a line graph of y versus x using matplotlib.

Matplotlib
plt.[1](x, y)
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bbar
Cplot
Dhist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' plots points without connecting lines.
Using 'bar' or 'hist' creates different chart types.
3fill in blank
hard

Fix the error in the code to downsample data by selecting every nth point.

Matplotlib
downsampled = data[[1]::n]
Drag options to blanks, or click blank then click option'
A1
B0
C-1
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 skips the first element.
Using -1 reverses the data.
Using n as start index skips too many elements.
4fill in blank
hard

Fill both blanks to create a dictionary of downsampled points where keys are indices and values are data points greater than threshold.

Matplotlib
downsampled_dict = {i: data[i] for i in range(0, len(data), [1]) if data[i] [2] threshold}
Drag options to blanks, or click blank then click option'
A5
B>
C<
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters points less than threshold.
Using 10 as step size changes downsampling rate.
Mixing operators causes wrong filtering.
5fill in blank
hard

Fill all three blanks to create a list of downsampled points squared, only if the point is less than max_val.

Matplotlib
result = [data[[1]]**2 for [2] in range(0, len(data), [3]) if data[i] < max_val]
Drag options to blanks, or click blank then click option'
Ai
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
Using wrong step size changes downsampling.
Forgetting to square the data point.