Reputation: 283
Here is the time series data. I'd like to read data file and plot it as candle chart. Actually, I googled to find pyghon logic I want all day long, But I couldn't. Any comments will be appreciated.
Thank you 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
Upvotes: 3
Views: 5362
Reputation: 239
You could consider plotly. Details on this link: https://plot.ly/python/candlestick-charts/
. If you want to achieve the same with matplotlib, then check out this link: https://pythonprogramming.net/candlestick-ohlc-graph-matplotlib-tutorial/
Upvotes: 0
Reputation: 25662
To read in this data set from the clipboard do
from pandas import read_clipboard
from 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 similarly to pandas.read_clipboard
, if you have this data sitting in a CSV or some other type of character-delimited file.
Now on to plotting:
from matplotlib.pyplot import subplots, draw
from 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
Upvotes: 2