This it the output of the script below
This plot was supposed to be an interactive. When you click a certain point such the one pointed by the red arrow, the plot title will show the coordinate and the data represented by the point.
# Modified from Coursera.org | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
plt.figure() | |
data = np.random.rand(10) | |
plt.plot(data, '-o') | |
# here we define what will happen when we click on certain pixel. | |
def asdf(event): | |
plt.gca().set_title('Event at pixels {},{} \nand data {},{}'.format(event.x, event.y, event.xdata, event.ydata)) | |
# tell mpl_connect we want to pass a 'button_press_event' into onclick when the event is detected | |
plt.gcf().canvas.mpl_connect('button_press_event', asdf) #mpl_connect is the key |