Thank you John,

Just what I was looking for.

John Hunter-4 wrote:
> 
> On Wed, Jul 30, 2008 at 9:17 AM, stuartornum <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> Wondering if anyone has done something similar and could point me in the
>> right direction.
>>
>> I have a dictionary like this:
>>
>> Dict{'00:00:00':'23', '00:01:00':'29', '00:02:00':'13', '00:03:00':'78',
>> '00:04:00':'45', >....> '23:59:00':54}
>>
>> So as you can see there is 24 hours worth of minutes, with a value
>> attached
>> to each minute.
>>
>> Firstly, just to note the Dictionary "Dict" is not actually in order as
>> above, it is all jumbled up.
>>
>> However is it possible to plot a dictionary using MatPlotLib, and using
>> the
>> time along the x-axis and values up the y?
> 
> You will have to extract the x and y values, and convert them from
> strings to values matplotlib can understand (for example dates and
> floating point numbers).  Eg
> 
> 
> In [30]: d = {'00:00:00':'23', '00:01:00':'29', '00:02:00':'13',
> '00:03:00':'78',
> '00:04:00':'45', '23:59:00':54}
> 
> In [32]: from dateutil.parser import parse
> 
> In [33]: items = [(parse(date), float(val)) for date, val in d.items()]
> 
> In [34]: items.sort()
> 
> In [35]: items
> Out[35]:
> [(datetime.datetime(2008, 7, 30, 0, 0), 23.0),
>  (datetime.datetime(2008, 7, 30, 0, 1), 29.0),
>  (datetime.datetime(2008, 7, 30, 0, 2), 13.0),
>  (datetime.datetime(2008, 7, 30, 0, 3), 78.0),
>  (datetime.datetime(2008, 7, 30, 0, 4), 45.0),
>  (datetime.datetime(2008, 7, 30, 23, 59), 54.0)]
> 
> In [36]: dates, values = zip(*items)
> 
> In [37]: plot(dates, values)
> Out[37]: [<matplotlib.lines.Line2D object at 0xb45a5ec>]
> 
> -------------------------------------------------------------------------
> 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@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Plot-a-Dictionary%2C-time-and-value-tp18734294p18750474.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to