Skip to content

Instantly share code, notes, and snippets.

@erikaris
Last active November 28, 2017 14:06
Show Gist options
  • Save erikaris/640d6ebb6b4ad86baa6a8457f1d008fc to your computer and use it in GitHub Desktop.
Save erikaris/640d6ebb6b4ad86baa6a8457f1d008fc to your computer and use it in GitHub Desktop.

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.

interactivity_line

# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment