Matplotlib Candlestick (Intraday) Chart is One Big Blob

前端 未结 2 1320
忘掉有多难
忘掉有多难 2020-12-06 15:01

I am trying to plot a Candlestick chart using Matplotlib with data I am acquiring for a REST API call. However since the call uses a unique access token I\'ve downloaded a s

相关标签:
2条回答
  • 2020-12-06 15:28

    It seems the undocumented width argument to candlestick_ohlc is the key. Multiply it by the fraction of a day between each of your data points. Since your data is in minute increments, this should do:

    candlestick_ohlc(ax, tuples, width=.6/(24*60), colorup='g', alpha =.4);
    

    To automate, use the difference between dates of successive data points. For example:

    width=0.6/(mdates.date2num(dates[1])-mdates.date2num(dates[0]))
    

    Note this turns out to be an FAQ, though the links are not obvious. See:

    • Charting Candlestick_OHLC one minute bars with Pandas and Matplotlib
    • python Matplotlib candlestick plot works only on daily data, not for intraday
    • Matplotlib candlestick in minutes
    0 讨论(0)
  • 2020-12-06 15:32

    Just change your width on the chart and it will be fine:

    candlestick_ohlc(ax1, ohlc, width=0.001, colorup='#77d879', colordown='#db3f3f')

    Tested using your data and it looks good.

    0 讨论(0)
提交回复
热议问题