Fluoborate <[EMAIL PROTECTED]> writes: > I really want to draw graphs where the X-axis is date/time. For > instance, I could graph the temperature over time, and the bottom > would say "January... February... March...". I have several questions > which I just can't figure out on my own: > > 1. What libraries/modules should I be using to draw these graphs?
I use pygdchart2. It doesn't seem to be actively maintained.
> 2. Is there any plotting library that understands datetime objects,
> and can graph them intelligently?
What I do is convert the dates with strftime. An example:
# get the data for the chart
cur.execute("""select date, current from dailystock
where symbol = %s and date >= (now() - interval %s)
order by date""", (symbol, interval))
rows = cur.fetchall()
dates = []
currents = []
for row in rows:
dates.append(row['date'].strftime('%b %d'))
currents.append(row['current'])
chart = gdchart.Line3D()
chart.width = 320
chart.height = 200
chart.title = '%s - %s' % (symbol, interval)
chart.set_color = ['blue']
chart.ylabel_density = 50
chart.ylabel_fmt = '%.02f'
chart.setData(currents)
chart.setLabels(dates)
chart.bg_color = 'white'
chart.plot_color = 'blue'
chart.line_color = 'black'
chart.bg_transparent = 1
# pygdchart2 can't write out to StringIO objects
fname = '/home/pkf/tmp/%s-%s.png' % (symbol, period)
chart.draw(fname)
f = file(fname)
return f.read()
The result looks like http://m.pkfinance.info/chart/ogdc/6m
Faried.
--
(> (length "eclipse") (length "emacs")) => T
pgpyfpBYvMM0A.pgp
Description: PGP signature
