From: Mark B. <ma...@gm...> - 2015-01-27 08:38:41
|
Thanks, Tom. I want to use ginput to draw a straight line on a graph. The line is used to select a cross-section of a contour plot. I was afraid it wasn't going to be easy. Getting to it from the other side, is there a matplotlib widget in the works where I can type text or numbers in a box? Like the FloatTextWidget in IPython? Problem is I want to make a small GUI that includes both a text widget (which is available in IPython) and a 'select points in graph' widget like ginput in matplotlib. Mark On Mon, Jan 26, 2015 at 11:47 PM, Thomas Caswell <tca...@gm...> wrote: > nbagg is always running in the IPython event loop (as I understand it), so > I am not sure how to integrate that with the blocking. > > On the 1.4.x/master branch we have support for (almost, one PR still > pending) all mouse and keyboard events so all of the mpl widgets should > work (big thanks to Steven Silvester). T > > What do you want to use that relies on ginput? > > You can fake up a non-blocking version something like: > > from collections import deque > ``` > class accumulator(object): > def __init__(self, n=5): > self.list_of_points = deque(maxlen=n) > > def on_event(self, event): > self.list_of_points.append(event) > > import matplotlib > import itertools > import numpy as np > matplotlib.use('nbagg') > import matplotlib.pyplot as plt > plt.close('all') > fig, ax = plt.subplots() > x = np.linspace(0,10,10000) > y = np.sin(x) > ln, = ax.plot(x,y) > > dd = accumulator(15) > fig.canvas.mpl_connect('button_press_event', dd.on_event) > plt.show() > ``` > > and then get the points by > > ``` > dd.lest_of_points > ``` > > This code obviously needs lots of bells and whistles, but points in the > right direction. > > Tom > > On Mon Jan 26 2015 at 2:45:45 PM Mark Bakker <ma...@gm...> wrote: > >> Hello List, >> >> Are there any plans to make ginput work in the nbagg backend? >> >> It would be so cool if I could use that in an IPython Notebook together >> with the other widgets. >> >> Thanks, >> >> Mark >> ------------------------------------------------------------ >> ------------------ >> > |