Great project, too cool to be able call gnuplot from inside python,
and on numpy arrays. One thing I haven't figured out yet is how to
get the fancier gnuplot styles to work, like errorbars and
candlesticks. If I have a multicolumn numpy record array X, how do I
pass it across to gnuplot so that plot recognises it as having the
five columns required by the candlestick style?
>>> g = get_backend()
>>> g('set style data candlestick')
>>>plot(X) # doesn't work
thanks,
sp
Try with g.plot(X) instead.
Johannes
>>>
scitools.easyviz backend is gnuplot
>>> X[-10:]
array([ (733807.0, 1.3903000000000001, 1.3903000000000001, 1.3729,
1.3737999999999999),
(733808.0, 1.3737999999999999, 1.3746, 1.3586, 1.3652),
(733811.0, 1.3652, 1.3714, 1.3622000000000001,
1.3658999999999999),
(733812.0, 1.3658999999999999, 1.3838999999999999,
1.3644000000000001, 1.3779999999999999),
(733813.0, 1.3779999999999999, 1.3815, 1.3677999999999999,
1.3732),
(733814.0, 1.3732, 1.3801000000000001, 1.3595999999999999,
1.3681000000000001),
(733815.0, 1.3681000000000001, 1.3695999999999999,
1.3532999999999999, 1.3609),
(733818.0, 1.3609, 1.3633999999999999, 1.3580000000000001,
1.3596999999999999),
(733819.0, 1.3596999999999999, 1.3778999999999999, 1.3589,
1.3765000000000001),
(733820.0, 1.3765000000000001, 1.3789, 1.3587, 1.3607)],
dtype=[('Date', '<f8'), ('O', '<f8'), ('H', '<f8'), ('L',
'<f8'), ('C', '<f8')])
>>> g = get_backend()
>>> g('set style candle')
>>> g.plot(X[-100:])
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
g.plot(X[-100:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/Gnuplot/_Gnuplot.py", line 284, in plot
self._add_to_queue(items)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/Gnuplot/_Gnuplot.py", line 254, in
_add_to_queue
self.itemlist.append(PlotItems.Data(item))
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/Gnuplot/PlotItems.py", line 549, in Data
data = utils.float_array(data[0])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/Gnuplot/utils.py", line 33, in float_array
return numpy.asarray(m, numpy.float32)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/numpy-1.4.0.dev7539-py2.5-macosx-10.3-fat.egg/
numpy/core/numeric.py", line 247, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
Am I misusing numpy record arrays? Is scitools just not going to work
with this kind of structured data?
If I use a list of lists instead, g.plot(X) works but I still don't
get the fancy plot styles from gnuplot that I'm after.
Sorry for the beginnerish questions.
Keiran
On Feb 26, 12:02 pm, Johannes Ring <joha...@simula.no> wrote:
> Hi,
>
> On Wed, Feb 24, 2010 at 12:38 AM, snakeplotter
>
The problem here lies with the Python interface to Gnuplot (the gnuplot-1.8
package), not with scitools, which is just a thin layer on top of the Gnuplot
package.
scitools.easyviz is a unified interface for curve plots and does not
support common styles for financial data. When you need to use these special
styles in, e.g., Gnuplot, I suggest that you don't plot via scitools,
but rather use Gnuplot directly, either through the Gnuplot module
(see the demo.py script that comes with the gnuplot-1.8 Python package),
or through a generated file in native Gnuplot language that you run by
os.system('gnuplot ' + gnuplotfile). The latter approach is foolproof
as you don't communicate arrays between Python and Gnuplot, but go
explicitly via files (you have to dump your data to a data file and
your commands to a command file in your Python program).
(For your particular problem, X[-100:].tolist() may help.)
Best regards,
Hans Petter
> --
> You received this message because you are subscribed to the Google Groups "scitools" group.
> To post to this group, send email to scit...@googlegroups.com.
> To unsubscribe from this group, send email to scitools+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/scitools?hl=en.
>