Ruby或Python中的财务图表/图表
发布时间:2020-12-16 19:48:18 所属栏目:百科 来源:网络整理
导读:在 Ruby或 Python等高级语言中创建财务开放高低关闭(OHLC)图表的最佳选择是什么?虽然似乎有很多图形的选择,我没有看到任何宝石或鸡蛋与这种图表. http://en.wikipedia.org/wiki/Open-high-low-close_chart(但我不需要移动平均线或布林带) JFreeChart可以在J
在
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() 创建一个这样的情节: 很明显,你想把它打包成一个使用(打开,关闭,最小,最大)元组绘制图形的函数(你可能不想随机分配你的开价和收盘价). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |