0
0
Matplotlibdata~10 mins

FuncAnimation for dynamic plots 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 function needed to create dynamic plots.

Matplotlib
from matplotlib.animation import [1]
Drag options to blanks, or click blank then click option'
Aplot
Bscatter
CFuncAnimation
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'plot' instead of 'FuncAnimation'.
Trying to import 'show' which is not for animation.
2fill in blank
medium

Complete the code to create a figure and axis for plotting.

Matplotlib
fig, ax = plt.[1]()
Drag options to blanks, or click blank then click option'
Aplot
Bfigure
Cshow
Dsubplots
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' which only creates a plot, not figure and axes.
Using 'figure' which creates only the figure, not axes.
3fill in blank
hard

Fix the error in the update function to correctly update the line data.

Matplotlib
def update(frame):
    y = [i**2 for i in range(frame)]
    line.set_data(range(frame), [1])
    return line,
Drag options to blanks, or click blank then click option'
Ay
Bx
Cframe
Dline
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'x' instead of 'y' to set_data.
Passing 'frame' which is just an integer, not data.
Passing 'line' which is the plot object, not data.
4fill in blank
hard

Fill both blanks to create the animation object with the correct figure and update function.

Matplotlib
ani = FuncAnimation([1], [2], frames=10, interval=200)
Drag options to blanks, or click blank then click option'
Afig
Bax
Cupdate
Dline
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis instead of figure as first argument.
Passing the line object instead of the update function.
5fill in blank
hard

Fill all three blanks to set the x and y limits and start the animation.

Matplotlib
ax.set_xlim(0, [1])
ax.set_ylim(0, [2])
plt.[3]()
Drag options to blanks, or click blank then click option'
A10
B100
Cshow
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Setting limits too small or too large causing plot to look empty.
Forgetting to call plt.show() to display the plot.