On 2012/07/25 12:45 PM, Scott Henderson wrote: > Thanks for the response. To be more specific, if I run the modified > script in an ipython --pylab terminal: > > In [1]: %run lasso_demo.py > > In [2]: > > The function returns, and the lasso manager is garbage collected as > you say. In other words, the plot shows up, but I can't draw a lasso > and select points. If I run the script in ipython without the pylab > flag it works! > > Why does enabling --pylab have this effect? Since I use pylab for > day-to-day computing I'd like to incorporate some of these widgit > tools in interactive sessions, but maybe that's not possible?
It is entirely possible. --pylab mode turns mpl interactive mode on, so that the call to show() does not block. But because you have that call inside your function, if show() doesn't block, you immediately return from the function, and as Tony noted, your widget gets garbage-collected. Try this: keep references to your figure and LassoManager in a list, dictionary, class, or whatever you like, and return that from your run() function. When you call run, assign its output to a name, so there is a reference to it, and indirectly to the LassoManager. Eric > > Thanks, > Scott > > > > On Jul 25, 2012, at 5:10 PM, Tony Yu wrote: > >> def run(points): >> data = [Datum(*xy) for xy in points] >> fig = figure() >> ax = fig.add_subplot(111, xlim=(0,1), ylim=(0,1), autoscale_on=False) >> lman = LassoManager(ax, data) >> show() >> >> if __name__ == '__main__': >> points = rand(100, 2) >> run(points) > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users