在
Ruby或
Python等高级语言中创建财务开放高低关闭(OHLC)图表的最佳选择是什么?虽然似乎有很多图形的选择,我没有看到任何宝石或鸡蛋与这种图表.
http://en.wikipedia.org/wiki/Open-high-low-close_chart(但我不需要移动平均线或布林带)
JFreeChart可以在Java中执行此操作,但我希望使我的代码尽可能小而简单.
谢谢!
解决方法
您可以使用
matplotlib和
matplotlib.pyplot.bar的可选底部参数.然后可以使用线条图来表示开盘价和收盘价:
例如:
#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt from matplotlib import lines import random deltas = [4,6,13,18,15,14,10,9,1,2,4,11,16,17,12,7,8,16] bases = [46,49,45,44,51,52,56,58,53,57,62,63,68,66,65,61,64,60,59,54,50,48,43,42,38,37,39,47,43] def rand_pt(bases,deltas): return [random.randint(base,base + delta) for base,delta in zip(bases,deltas)] # randomly assign opening and closing prices openings = rand_pt(bases,deltas) closings = rand_pt(bases,deltas) # First we draw the bars which show the high and low prices # bottom holds the low price while deltas holds the difference # between high and low. width = 0 ax = plt.axes() rects1 = ax.bar(np.arange(50),deltas,width,color='r',bottom=bases) # Now draw the ticks indicating the opening and closing price for opening,closing,bar in zip(openings,closings,rects1): x,w = bar.get_x(),0.2 args = { } ax.plot((x - w,x),(opening,opening),**args) ax.plot((x,x + w),(closing,closing),**args) plt.show()
创建一个这样的情节: