0
0
Matplotlibdata~10 mins

Highlight and annotate pattern 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'
Aplot
Bpyplot
Cgraph
Dcharts
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot' causes import errors.
Trying to import 'graph' or 'charts' which are not matplotlib modules.
2fill in blank
medium

Complete the code to plot a line graph using x and y data.

Matplotlib
plt.[1](x, y)
plt.show()
Drag options to blanks, or click blank then click option'
Ahist
Bscatter
Cbar
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' plots points but does not connect them with lines.
Using 'bar' or 'hist' creates different chart types.
3fill in blank
hard

Fix the error in the code to add an annotation at point (2, 4) with text 'Peak'.

Matplotlib
plt.annotate('Peak', xy=(2, 4), xytext=[1], arrowprops=dict(facecolor='black'))
plt.show()
Drag options to blanks, or click blank then click option'
A(3, 5)
B[3, 5]
C'3, 5'
D3, 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for xytext.
Passing coordinates as a string or separate arguments.
4fill in blank
hard

Fill both blanks to highlight the region between x=1 and x=3 with a light blue color.

Matplotlib
plt.fill_between(x, y, where=(x [1] 1) & (x [2] 3), color='lightblue', alpha=0.5)
plt.show()
Drag options to blanks, or click blank then click option'
A>=
B<=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' incorrectly reverses the highlighted region.
Not using both conditions combined with &.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

Matplotlib
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not filtering words by length > 3.