[Matplotlib-users] plotting from a dictionary

2008-04-03 Thread Chris Withers
Hey All,

I have a dictionary that maps date to a count (in this case the number 
of false negatives from my spam filter) and I'm wondering how to best 
plot something that looks like, say:

from datetime import date
data = {
   date(2008,03,01):10,
   date(2008,03,02):15,
   date(2008,03,03):13,
}

I'm worried about getting the dates out in order such that I get a 
straight line plot, rather than the zigzag back-and-forth line I reckon 
I'd get if I did:

dates = []
count = []
for date,count in data.items:
   dates.append(date)
   count.append(count)

plot(dates,counts)

cheers,

Chris

-- 
Simplistix - Content Management, Zope  Python Consulting
- http://www.simplistix.co.uk

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plotting from a dictionary

2008-04-03 Thread Pierre GM
Chris,

Why wouldn't you try to use sorted on your dictionary, construct an array from 
the result of sorted, and get the corresponding columns ?

ddict={date(2008,01,01):10,date(2008,01,03):20,date(2008,01,02):30}
results=numpy.array(sorted(ddict.iteritems()),)
print results[:,0]
[2008-01-01 2008-01-02 2008-01-03]
print results[:,1]
[10 30 20]

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users