matplotlib-users

 [Matplotlib-users] list of tuples vs tuple of lists From: Thomas Guettler - 2008-10-23 13:23:09 ```Hi, I use the API of matplotlib and have a basic problem: Up to now I am used to gather my data into a list of tuples. But matplotlib uses serveral lists instead. Example: me: [(date1, count1), (date2, count2), ...] matplotlib: ax.plot_date(dates, counts) Finally I use something like this quite often: method([item[0] for item in items], [item[1] for item in items]) But I think thats to much looping. That's my personal problem, but I think a more pythonic API would be nice... Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de ```
 Re: [Matplotlib-users] list of tuples vs tuple of lists From: Michael Droettboom - 2008-10-23 13:35:41 ```You could use the (admittedly inscrutable) "unzip" technique: ax.plot_date(*zip(*items)) See this blog post for explanation: http://paddy3118.blogspot.com/2007/02/unzip-un-needed-in-python.html If you use Numpy arrays, of course, you could use slicing, which, IMHO, is clearer: items = numpy.asarray(items) ax.plot_date(items[:,0], items[:,1]) Mike Thomas Guettler wrote: > Hi, > > I use the API of matplotlib and have a basic problem: > > Up to now I am used to gather my data into a list of tuples. But > matplotlib uses serveral lists instead. > > Example: > me: [(date1, count1), (date2, count2), ...] > matplotlib: ax.plot_date(dates, counts) > > Finally I use something like this quite often: > method([item[0] for item in items], [item[1] for item in items]) > But I think thats to much looping. > > That's my personal problem, but I think a more pythonic > API would be nice... > > Thomas > > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA ```
 Re: [Matplotlib-users] list of tuples vs tuple of lists From: Brent Pedersen - 2008-10-23 15:27:37 ```On Thu, Oct 23, 2008 at 6:35 AM, Michael Droettboom wrote: > You could use the (admittedly inscrutable) "unzip" technique: > > ax.plot_date(*zip(*items)) > > See this blog post for explanation: > > http://paddy3118.blogspot.com/2007/02/unzip-un-needed-in-python.html > > If you use Numpy arrays, of course, you could use slicing, which, IMHO, > is clearer: > > items = numpy.asarray(items) > ax.plot_date(items[:,0], items[:,1]) if items is a numpy array you can even do: >>> pylab.plot(*items.T) > > Mike > > Thomas Guettler wrote: >> Hi, >> >> I use the API of matplotlib and have a basic problem: >> >> Up to now I am used to gather my data into a list of tuples. But >> matplotlib uses serveral lists instead. >> >> Example: >> me: [(date1, count1), (date2, count2), ...] >> matplotlib: ax.plot_date(dates, counts) >> >> Finally I use something like this quite often: >> method([item[0] for item in items], [item[1] for item in items]) >> But I think thats to much looping. >> >> That's my personal problem, but I think a more pythonic >> API would be nice... >> >> Thomas >> >> > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```