
线段图是可行的,然则每一天的数据至少有四个变量(开市,股票最高价,股票最低价和闭市),我们欲望找到一种不须要我们画四条不合的线就能看到这四个变量走势的可视化办法。一般来说我们应用烛柱图(也称为日本阴阳烛图表)来可视化金融数据,烛柱图最早在18世纪被日本的稻米商人所应用。可以用matplotlib来作图,然则须要费些工夫。
你们可以应用我实现的一个函数更轻易地画烛柱图,它接收pandas的data frame作为数据来源。(法度榜样基于这个例子, 你可以大年夜这里找到相干函数的文档。)
- from matplotlib.dates import DateFormatter, WeekdayLocator,\
- DayLocator, MONDAY
- from matplotlib.finance import candlestick_ohlc
- def pandas_candlestick_ohlc(dat, stick = "day", otherseries = None):
- """
- :param dat: pandas DataFrame object with datetime64 index, and float columns "Open", "High", "Low", and "Close", likely created via DataReader from "yahoo"
- :param stick: A string or number indicating the period of time covered by a single candlestick. Valid string inputs include "day", "week", "month", and "year", ("day" default), and any numeric input indicates the number of trading days included in a period
- :param otherseries: An iterable that will be coerced into a list, containing the columns of dat that hold other series to be plotted as lines
- This will show a Japanese candlestick plot for stock data stored in dat, also plotting other series if passed.
- """
- mondays = WeekdayLocator(MONDAY) # major ticks on the mondays
- alldays = DayLocator() # minor ticks on the days
- dayFormatter = DateFormatter('%d') # e.g., 12
- # Create a new DataFrame which includes OHLC data
推荐阅读
【51CTO.com原创稿件】由51CTO主办的WOTA2017全球立异技巧峰会将于2017年7月21日拉开帷幕。本次峰会,将环绕机>>>详细阅读
本文标题:用Python做股市数据分析(一)
地址:http://www.17bianji.com/lsqh/36070.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示