Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Interactive Applications using Matplotlib

You're reading from  Interactive Applications using Matplotlib

Product type Book
Published in Mar 2015
Publisher
ISBN-13 9781783988846
Pages 174 pages
Edition 1st Edition
Languages

Picking


We demonstrated pick events earlier, showing how to select a storm track, changing its thickness, but we haven't incorporated picking into our current design yet. Much in the same vein as the KeymapControl class, let's create a PickControl class that will keep a list of pick functions (pickers) and manage their connection to the callback system for us:

Source: chp2/select_stormcells.py

class PickControl:
    def __init__(self, fig):
        self.fig = fig
        self._pickers = []
        self._pickcids = []

    def connect_picks(self):
        for i, picker in enumerate(self._pickers):
            if self._pickcids[i] is None:
                cid = self.fig.canvas.mpl_connect('pick_event', picker)
                self._pickcids[i] = cid

    def disconnect_picks(self):
        for i, cid in enumerate(self._pickcids):
            if cid is not None:
                self.fig.canvas.mpl_disconnect(cid)
                self._pickcids[i] = None

    def add_pick_action(self, picker...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}