K
Kurt Schwehr
Hi all,
What's the best way to pull arrays from a database for plotting?
Right now, this is what I do, but can it be done simpler / more
efficiently?
ipython -pylab
import sqlite3
cx = sqlite3.connect('20080407.decimated.db3')
a = array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] )
x = a[:,0]
y = a[:,1]
plot(x,y)
However, if I try to plot it directly using transpose, it hangs:
import sqlite3
cx = sqlite3.connect('20080407.decimated.db3')
plot(array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] ).transpose())
It is that plot just doesn't know what to do with a 2D array? Then I
tried this and it works, but is long and confusing to the uninitiated.
plot(*array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] ).T)
In [4]: a
Out[4]:
array([[ 2.40000000e+01, 0.00000000e+00],
[ 2.50000000e+01, -1.00000000e+00],
[ 3.40000000e+01, 0.00000000e+00],
...,
[ 8.63840000e+04, 2.00000000e+01],
[ 8.63940000e+04, 2.00000000e+01],
[ 8.64040000e+04, 2.00000000e+01]])
In [5]: a.transpose()
Out[5]:
array([[ 2.40000000e+01, 2.50000000e+01, 3.40000000e+01, ...,
8.63840000e+04, 8.63940000e+04, 8.64040000e+04],
[ 0.00000000e+00, -1.00000000e+00, 0.00000000e+00, ...,
2.00000000e+01, 2.00000000e+01, 2.00000000e+01]])
What's the best way to pull arrays from a database for plotting?
Right now, this is what I do, but can it be done simpler / more
efficiently?
ipython -pylab
import sqlite3
cx = sqlite3.connect('20080407.decimated.db3')
a = array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] )
x = a[:,0]
y = a[:,1]
plot(x,y)
However, if I try to plot it directly using transpose, it hangs:
import sqlite3
cx = sqlite3.connect('20080407.decimated.db3')
plot(array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] ).transpose())
It is that plot just doesn't know what to do with a 2D array? Then I
tried this and it works, but is long and confusing to the uninitiated.
plot(*array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] ).T)
In [4]: a
Out[4]:
array([[ 2.40000000e+01, 0.00000000e+00],
[ 2.50000000e+01, -1.00000000e+00],
[ 3.40000000e+01, 0.00000000e+00],
...,
[ 8.63840000e+04, 2.00000000e+01],
[ 8.63940000e+04, 2.00000000e+01],
[ 8.64040000e+04, 2.00000000e+01]])
In [5]: a.transpose()
Out[5]:
array([[ 2.40000000e+01, 2.50000000e+01, 3.40000000e+01, ...,
8.63840000e+04, 8.63940000e+04, 8.64040000e+04],
[ 0.00000000e+00, -1.00000000e+00, 0.00000000e+00, ...,
2.00000000e+01, 2.00000000e+01, 2.00000000e+01]])