From list of objects to plotting

Tommy Grav <tgrav@...935...> writes:

I would now like to plot a vs e for all the obj objects in nlist.
how do I do that? I tried

plot(nlist[:].a,nlist[:].e,'ko')

You have a list of objects that have attributes named a and e; these
are not attributes of the list. Try

  plot([x.a for x in nlist], [x.e for x in nlist], 'ko')

···

--
Jouni K. Sepp�nen

Another idiom which I use a lot

  a,e = zip(*[(o.a, o.e) for o in nlist])

or if I have a lot of attributes I want dumped into arrays

  a,b,c,d = map(numpy.asarray, zip(*[(o.a, o.b, o.c, o.d) for o in data]))

JDH

···

On 5/6/07, Jouni K. Seppänen <jks@...397...> wrote:

Tommy Grav <tgrav@...935...> writes:

> I would now like to plot a vs e for all the obj objects in nlist.
> how do I do that? I tried
>
> plot(nlist[:].a,nlist[:].e,'ko')

You have a list of objects that have attributes named a and e; these
are not attributes of the list. Try

  plot([x.a for x in nlist], [x.e for x in nlist], 'ko')