Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the module needed for plotting.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing numpy or pandas instead of matplotlib.pyplot.
Using seaborn which is a different plotting library.
✗ Incorrect
We use matplotlib.pyplot for plotting graphs and handling cursor events.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.figure() which returns only the figure.
Using plt.plot() which creates a plot but not figure and axes separately.
✗ Incorrect
The subplots() function creates a figure and axes for plotting.
3fill in blank
hardFix the error in the event connection code to correctly connect the cursor move event.
Matplotlib
cid = fig.canvas.[1]('motion_notify_event', on_move)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like connect_event or add_event.
Trying to use bind which is not a matplotlib method.
✗ Incorrect
The correct method to connect events in matplotlib is connect.
4fill in blank
hardFill both blanks to create a cursor object and enable it on the axis.
Matplotlib
cursor = Cursor([1], useblit=True, color='red', linewidth=1) cursor.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing figure instead of axis to Cursor.
Using a non-existent method like enable() instead of draw().
✗ Incorrect
The cursor is created on the axis ax and draw() is called to enable it.
5fill in blank
hardFill all three blanks to create a function that prints cursor coordinates on mouse move.
Matplotlib
def on_move(event): if event.inaxes == [1]: x, y = event.[2], event.[3] print(f"Cursor at: ({x:.2f}, {y:.2f})")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking event.inaxes against figure instead of axis.
Using event.x and event.y which are pixel positions, not data coordinates.
✗ Incorrect
The event's inaxes is compared to ax. Coordinates are accessed via xdata and ydata.