I was trying to plot a candlestick graph using stock data extracted from quandl. However, the graph looks eerie, only a few bars showed up. I have no idea what is going on. Any help is greatly appreciated.
Here is the code:
start=dt.datetime(2000,1,1)
end=dt.datetime(2017,9,20)
df=quandl.get('WIKI/TWTR',start_date=start,end_date=end)
date_val=[x for x in range(len(df.index))]
open_val=np.array(df['Adj. Open'],dtype=np.float64)
high_val=np.array(df['Adj. High'],dtype=np.float64)
low_val=np.array(df['Adj. Low'],dtype=np.float64)
close_val=np.array(df['Adj. Close'],dtype=np.float64)
ohlc_data=[date_val,open_val,high_val,low_val,close_val]
ax1=plt.subplot(111)
candlestick_ohlc(ax1,ohlc_data,width=0.9,colorup='g',colordown='r',alpha=0.8)
plt.show()
This is the graph:
There are two major issue here.
The dates should be numeric values corresponding to the dates in question.
candlestick_ohlc
needs to be a sequence of sequences, i.e. each datum needs to be in it individually as(time, open, high, low, close, ...)
.A possible solution:
Or, more consise: