[Matplotlib-users] Arrows with circular curvature
I am trying to draw plasmid maps in matplotlib. This requires drawing arrows with a circular curvature (see here for example http://www.encyclon.net/docs/plasmidmap/images/ex6.gif). However, when I try to curve the arrows, for instance using this example ( http://matplotlib.org/api/artist_api.html#matplotlib.patches.ArrowStyle), I can only get parabolic type curves, not circular curves. Can someone who understands this a little better help me out with a simple example? Thanks, Mark -- AlienVault Unified Security Management (USM) platform delivers complete security visibility with the essential security capabilities. Easily and efficiently configure, manage, and operate all of your security controls from a single console and one unified framework. Download a free trial. http://p.sf.net/sfu/alienvault_d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Using the lasso tool when file is not main
Thanks Ben, that solved my issue. I guess I got thrown off because the plot stayed open, as you described. It's hard to troubleshoot when you don't get any errors. In the future I will attach all of my objects. -Mark On Fri, Sep 7, 2012 at 12:03 PM, Benjamin Root ben.r...@ou.edu wrote: I think I see your problem... see below: class start_lasso(): def __init__(self): data = [Datum(*xy) for xy in rand(100, 2)] fig = figure() ax = fig.add_subplot(111, xlim=(0,1), ylim=(0,1), autoscale_on=False) lman = LassoManager(ax, data) show() You aren't saving any of the objects created in the start_lasso class to your start_lasso object. Luckily, with the way pyplot works, the figure object your create gets implicitly saved to the pyplot state manager (a sort of smart global location for the figure objects), and the axes object gets implicitly attached to the figure object. Therefore, when the python execution goes out of this scope, the figure object and the axes do not get garbage-collected. However, the lasso widget that gets created and all the callbacks that were attached are all done with weak references to the figure and axes. So when you leave this scope, the LassoManager no longer exists and the callback fails to execute (as designed). So, make sure that at least lman (and possibly fig and ax) gets saved to the start_lasso object to solve that part of the problem. Next, you don't save the start_lasso object your create anywhere, so even if you saved lman to start_lasso, the start_lasso object gets garbage-collected anyway as a temporary. I hope this is clear. Let me know if you still have more issues. Cheers! Ben Root -- 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
Re: [Matplotlib-users] Using the lasso tool when file is not main
On closer inspection the problem isn't calling it from another file, it is calling it from wxpython. Not exactly sure how to copy code... lasso_test.py - from matplotlib.widgets import Lasso from matplotlib.nxutils import points_inside_poly from matplotlib.colors import colorConverter from matplotlib.collections import RegularPolyCollection from matplotlib.pyplot import figure, show from numpy import nonzero from numpy.random import rand from scipy import linspace, polyval, polyfit, sqrt, stats, randn class Datum: colorin = colorConverter.to_rgba('red') colorout = colorConverter.to_rgba('green') def __init__(self, x, y, include=False): self.x = x self.y = y if include: self.color = self.colorin else: self.color = self.colorout class LassoManager: def __init__(self, ax, data): self.axes = ax self.canvas = ax.figure.canvas self.data = data self.Nxy = len(data) facecolors = [d.color for d in data] self.xys = [(d.x, d.y) for d in data] fig = ax.figure self.collection = RegularPolyCollection( fig.dpi, 6, sizes=(100,), facecolors=facecolors, offsets = self.xys, transOffset = ax.transData) ax.add_collection(self.collection) self.cid = self.canvas.mpl_connect('button_press_event', self.onpress) self.ind = None def callback(self, verts): if hasattr(self, 'temp'): self.temp.pop(0).remove() facecolors = self.collection.get_facecolors() ind = nonzero(points_inside_poly(self.xys, verts))[0] selected = [] for i in range(self.Nxy): if i in ind: facecolors[i] = Datum.colorin selected.append(self.xys[i]) else: facecolors[i] = Datum.colorout xs = [] ys = [] for n in selected: xs.append(n[0]) ys.append(n[1]) (ar,br) = polyfit(xs,ys,1) t = linspace(min(xs),max(xs)) print('ar=%s br=%s' % (ar,br)) xr = polyval([ar,br],t) self.temp = self.axes.plot(t,xr,'-',c='b') self.canvas.draw_idle() self.canvas.widgetlock.release(self.lasso) del self.lasso self.ind = ind def onpress(self, event): print('clicked') if self.canvas.widgetlock.locked(): return if event.inaxes is None: return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback) # acquire a lock on the widget drawing #self.canvas.widgetlock(self.lasso) class start_lasso(): def __init__(self): data = [Datum(*xy) for xy in rand(100, 2)] fig = figure() ax = fig.add_subplot(111, xlim=(0,1), ylim=(0,1), autoscale_on=False) lman = LassoManager(ax, data) show() call_lasso.py import wx import lasso_test class MyFrame(wx.Frame): We simply derive a new class of Frame. def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(200,100)) button = wx.Button(self, label='Open Lasso') self.Bind(wx.EVT_BUTTON, self.open_lasso, button) self.Show(True) def open_lasso(self, event): lasso_test.start_lasso() app = wx.App(False) frame = MyFrame(None, 'Small editor') app.MainLoop() - Thanks, Mark On Wed, Sep 5, 2012 at 5:15 PM, Tony Yu tsy...@gmail.com wrote: On Wed, Sep 5, 2012 at 7:19 PM, Mark Budde markbu...@gmail.com wrote: Hi, I'm not an expert so please go easy on me. I am using the pyplot lasso demo, and have got it to work how I would like. I am having a problem, however, where I cannot get it to work if my python file is not the main file (where __name__ is not __main__). I took the part at the bottom in the if __name__ == '__main__': and put it into a class. Everything works fine if I call the class from within the same file. However, if I call the class from another file, the graph loads fine but the lasso tool does not work. Troubleshooting revealed that LassoManager.onpress is not being called when I click the mouse. Any suggestions are welcome because this is driving me crazy! Thanks, Mark Hi Mark, I can't seem to reproduce your issue, but it's a bit difficult without seeing how exactly you wrapped up the main part of the code. Just guessing: maybe the two cases aren't *exactly* the same. Is it possible that you have ``lman`` (the LassoManager instance) defined in the same block of code as ``show`` in one case but not the other? If, for example, ``lman`` is defined in a method of your class, but not saved anywhere then it'll get discarded after the method finishes. So ``show`` would need to be called inside that method, or saved as a class attribute. Like I said, that's just a wild guess. You should paste the class def if you're still having
[Matplotlib-users] Using the lasso tool when file is not main
Hi, I'm not an expert so please go easy on me. I am using the pyplot lasso demo, and have got it to work how I would like. I am having a problem, however, where I cannot get it to work if my python file is not the main file (where __name__ is not __main__). I took the part at the bottom in the if __name__ == '__main__': and put it into a class. Everything works fine if I call the class from within the same file. However, if I call the class from another file, the graph loads fine but the lasso tool does not work. Troubleshooting revealed that LassoManager.onpress is not being called when I click the mouse. Any suggestions are welcome because this is driving me crazy! Thanks, Mark -- 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