pythonpandasmatplotlibstockscandlestick-chart

plotting candlesticks with ticks of 1 minute


I'm trying to plot candlestick_ohlc with ticks of 1 minute and the graph looks like this:

plot result

I looked on the site and i tried to implement all the answers about questions like this, and yet, the result was the same grpah.

I think the the problem is in the tick rate of the x axis, but cant figure how to fix it.

Here is the part from the code that plotting the graph: (the prints are there so you will be able to understand which data is used (added pastebin link)

print(data_ohlc)
df_ohlc = pd.DataFrame(data_ohlc, columns=['Date', 'Open', 'High', 'Low', 'Close'])
print(df_ohlc)
df_ohlc['Date'] = df_ohlc['Date'].map(mdates.date2num)
print(df_ohlc['Date'])
fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
candlestick_ohlc(ax, df_ohlc.values, width=2, colorup='g')
plt.show()

the data i used can be found here:

https://pastebin.com/qm5KFyrx

Solution

  • You're trying to fit 3 days worth of 1 minute data (that's 24 * 60 * 3 = 4320 points) into a 300x400 pixel picture? No wonder it won't fit. Try to display the smaller sections of your data, take first 100 points for example, work with them -- I'm sure you'll get the reasonable picture from that.