Complete the code to connect the pick event handler to the figure.
fig.canvas.mpl_connect('[1]', on_pick)
The pick_event is the event triggered when a pickable artist is clicked.
Complete the code to make the scatter plot points pickable.
scatter = ax.scatter(x, y, picker=[1])Setting picker=True makes the scatter points respond to pick events.
Fix the error in the pick event handler to print the index of the picked point.
def on_pick(event): ind = event.ind[[1]] print(f"Picked point index: {ind}")
The event.ind is a list of indices; use 0 to get the first picked point.
Fill both blanks to create a pick event handler that changes the color of the picked point to red.
def on_pick(event): ind = event.ind[0] scatter._facecolors[ind] = [1] scatter.figure.canvas.[2]()
Set the facecolor to red using RGBA [1,0,0,1] and refresh the canvas with draw_idle().
Fill all three blanks to create a dictionary comprehension that maps point indices to their x-coordinates for points with x > 0.5.
selected_points = [1]: x[[2]] for [1] in range(len(x)) if x[[2]] > 0.5}
Use i as the index variable and key, and access x[i] for values and condition.