python - How to read and plot time series data files as candlestick chart? -
here time series data. i'd read data file , plot candle chart. actually, googled find pyghon logic want day long, couldn't. comments appreciated.
thank in advance.
2011-11-01 9:00:00, 248.50, 248.95, 248.20, 248.70 2011-11-01 9:01:00, 248.70, 249.00, 248.65, 248.85 2011-11-01 9:02:00, 248.90, 249.25, 248.70, 249.15 2011-11-01 9:03:00, 249.20, 249.60, 249.10, 249.60 2011-11-01 9:04:00, 249.55, 249.95, 249.50, 249.60 2011-11-01 9:05:00, 249.60, 249.85, 249.55, 249.75 2011-11-01 9:06:00, 249.75, 250.15, 249.70, 249.85 2011-11-01 9:07:00, 249.85, 250.15, 249.80, 250.15 2011-11-01 9:08:00, 250.10, 250.40, 250.00, 250.15 2011-11-01 9:09:00, 250.20, 250.35, 250.10, 250.20
to read in data set clipboard do
from pandas import read_clipboard matplotlib.dates import date2num names = ['date', 'open', 'close', 'high', 'low'] df = read_clipboard(sep=',', names=names, parse_dates=['date']) df['d'] = df.date.map(date2num)
the top-level pandas.read_csv
function works pandas.read_clipboard
, if have data sitting in csv or other type of character-delimited file.
now on plotting:
from matplotlib.pyplot import subplots, draw matplotlib.finance import candlestick seconds_per_day = 60 * 60 * 24 fig, ax = subplots() candlestick(ax, df[['d', 'open', 'close', 'high', 'low']].values, width=1.0 / seconds_per_day) ax.xaxis_date() draw()
gives
Comments
Post a Comment