[IPython-dev] Text output from matplotlib event not shown
Antonino Ingargiola
tritemio at gmail.com
Fri Apr 18 02:56:54 EDT 2014
For the record, I tried running the plot from a qtconsole and the text
output is correctly printed. So it is a notebook specific issue.
Antonio
On Thu, Apr 17, 2014 at 10:57 PM, Antonino Ingargiola <tritemio at gmail.com>wrote:
> Hi,
>
> in IPython Notebook 1.x I built some QT matplotlib plots that allow to
> select a range (with the mouse) and print to the range boundaries, or
> related information.
>
> To do that I connect a callback to the standard matplotlib events. The
> callback draws a range highlight and prints the range info.
>
> In IPython 2.0 I can't get the print output anymore, although the range is
> drawn and therefore I'm sure the callback is called. I thought that the
> issue can be related to:
>
> https://github.com/ipython/ipython/issues/5408
>
> If this is the same issue, are they any workaround I can use to get the
> output back?
>
> For completeness I attach the main class I use for the interactive range
> selection:
>
> class GuiSelection(object):
> """Abstract class for range selection.
>
> Methods on_press_draw(), on_motion_draw() and on_release_print() must
> be overloaded by children classes.
> """
> def __init__(self, fig, ax, debug=False):
> self.ax = ax
> self.fig = fig
> self.pressed = False
> self.debug = debug
> self.id_press = fig.canvas.mpl_connect('button_press_event',
> self.on_press)
> if self.debug:
> print 'Figure:', fig, '\nAxis:', ax
> def on_press(self, event):
> if event.inaxes != self.ax: return
> self.pressed = True
> self.xs, self.ys = event.xdata, event.ydata
> if self.debug:
> pprint('PRESS button=%d, x=%d, y=%d, xdata=%f, ydata=%f\n' % (
> event.button, event.x, event.y, event.xdata, event.ydata))
> self.on_press_draw()
> self.fig.canvas.draw()
> self.id_motion = self.fig.canvas.mpl_connect('motion_notify_event',
> self.on_motion)
> self.fig.canvas.mpl_connect('button_release_event',
> self.on_release)
>
> def on_motion(self, event):
> if event.inaxes != self.ax: return
> if self.debug:
> pprint('MOTION x=%d, y=%d, xdata=%f, ydata=%f\n' % (
> event.x, event.y, event.xdata, event.ydata))
> self.xe, self.ye = event.xdata, event.ydata
> self.on_motion_draw()
> self.fig.canvas.draw()
>
> def on_release(self, event):
> if not self.pressed: return
> self.pressed = False
> if self.debug:
> pprint('RELEASE button=%d, x=%d, y=%d, xdata=%f, ydata=%f\n' %
> (
> event.button, event.x, event.y, event.xdata, event.ydata))
> self.fig.canvas.mpl_disconnect(self.id_motion)
> self.on_release_print()
>
> def on_press_draw(self):
> pass
>
> def on_motion_draw(self):
> pass
>
> def on_release_print(self):
> pass
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140417/b9597822/attachment.html>
More information about the IPython-dev
mailing list