On Wed, Sep 21, 2011 at 2:00 PM, Armando Serrano Lombillo <
arser...@gmail.com> wrote:
> Hello I have a dat set like this one
> a=[[x1, y1, cat1], [x2, y2, cat1], ..., [x8, y8, cat1], [x9, y9, cat2],
> ..., [x34, y34, cat2], [x35, y35, cat3],...]
> and I don't know beforehand how many diffferent categories there will be or
> how long they will be.
>
> I would like to make a plot like this:
> ax.plot(a[0:i1, 0], a[0:i1, 1], label=cat1)
> ax.plot(a[i1:i2, 0], a[i1:i2, 1], label=cat2)
> ax.plot(a[i2:i3, 0], a[i2:i3, 1], label=cat3)
> ...
>
> where i1, i2... are the indices where the data set changes fomt cat1 to
> cat2, cat2 to cat3...
>
> Does anybody see an easy way of coding this?
>
> Thanks,
> Armando.
>
Maybe something like this? (Warning: untested!)
from collections import OrderedDict
b = OrderedDict()
for index, coords in enumerate(a) :
b[coords[2]] = index + 1
a = np.array([[c[0], c[1]] for c in a])
prevIndex = 0
for cat, curIndex in b.iteritems() :
ax.plot(a[prevIndex:curIndex, 0], a[prevIndex:curIndex, 1], label=cat)
prevIndex = curIndex
The ordered dictionary may or may not be available in whatever version of
python you use, but it guarantees the order.
I hope that helps!
Ben Root
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users