0
0
Matplotlibdata~10 mins

Animation update function 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 animation module from matplotlib.

Matplotlib
from matplotlib import [1]
Drag options to blanks, or click blank then click option'
Apyplot
Bfigure
Canimation
Daxes
Attempts:
3 left
💡 Hint
Common Mistakes
Importing pyplot instead of animation
Using figure or axes which are not for animation
2fill in blank
medium

Complete the update function to set new y-data for the line in the animation.

Matplotlib
def update(frame):
    y = [i * frame for i in range(5)]
    line.set_[1](y)
    return line,
Drag options to blanks, or click blank then click option'
Adata
Bxdata
Cvalues
Dydata
Attempts:
3 left
💡 Hint
Common Mistakes
Using set_xdata instead of set_ydata
Using set_data which requires both x and y
3fill in blank
hard

Fix the error in the update function to correctly return the updated line object as a tuple.

Matplotlib
def update(frame):
    y = [frame + i for i in range(5)]
    line.set_ydata(y)
    return [1]
Drag options to blanks, or click blank then click option'
A(line,)
Bline,
C[line]
Dline
Attempts:
3 left
💡 Hint
Common Mistakes
Returning just line without tuple
Returning a list instead of a tuple
4fill in blank
hard

Fill both blanks to create an animation object that updates the line every 100 milliseconds for 50 frames.

Matplotlib
ani = animation.FuncAnimation(fig, [1], frames=[2], interval=100)
Drag options to blanks, or click blank then click option'
Aupdate
Bline
C50
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using line instead of update function
Setting frames to 100 instead of 50
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length 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)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using item instead of word
Using word instead of len(word) as value