Skip to content

Instantly share code, notes, and snippets.

@blink1073
Created December 6, 2013 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blink1073/7822896 to your computer and use it in GitHub Desktop.
Save blink1073/7822896 to your computer and use it in GitHub Desktop.
Enaml MPLCanvas Event Demo
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 06 06:07:21 2013
@author: Steven Silvester <steven.silvester@ieee.org>
@license: MIT
"""
import functools
import matplotlib.pyplot as plt
import numpy as np
from numpy.random import rand
from enaml.widgets.api import MainWindow, Label, MPLCanvas, Container
x, y, c, s = rand(4, 100)
fig, ax = plt.subplots()
col = ax.scatter(x, y, 100*s, c, picker=True)
def update_label(window, event):
ind = event.ind
label = window.find('picker_label')
label.text = '%s %s %s' % (ind, np.take(x, ind), np.take(y, ind))
enamldef Main(MainWindow):
activated ::
fig.canvas.mpl_connect('pick_event',
functools.partial(update_label, self))
Container:
MPLCanvas:
figure = fig
Label:
name = 'picker_label'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment