Home > Software engineering >  matplotlib only plotting date instead of given datetime variable
matplotlib only plotting date instead of given datetime variable

Time:06-08

I am trying to plot candle sticks but for some reason, the plot does not grab the entire DateTime variable. But only the date. Plotting all candles on the same X axis rather than all 15 min as the data is given in.

Following code.

        ##  PLOT Candles
        plt.figure()

        #define width of candlestick elements
        width = .5
        width2 = .05

        #define up and down prices
        up = df[df.close>=df.open]
        down = df[df.close<df.open]
        print(up)
        #define colors to use
        col1 = 'green'
        col2 = 'red'
        col3 = 'blue'
        col4 = 'grey'

        #plot up prices
        plt.bar(up.index,up.close-up.open,width,bottom=up.open,color=col1)
        plt.bar(up.index,up.high-up.close,width2,bottom=up.close,color=col1)
        plt.bar(up.index,up.low-up.open,width2,bottom=up.open,color=col1)

        #plot down prices
        plt.bar(down.index,down.close-down.open,width,bottom=down.open,color=col2)
        plt.bar(down.index,down.high-down.open,width2,bottom=down.open,color=col2)
        plt.bar(down.index,down.low-down.close,width2,bottom=down.close,color=col2)
        
        plt.show()
        exit()

Following is the print of up enter image description here

enter image description here

print(df[:5].to_dict())

{'open': {Timestamp('2016-01-14 08:15:00'): 1.08719, Timestamp('2016-01-14 08:30:00'): 1.08735, Timestamp('2016-01-14 08:45:00'): 1.08674, Timestamp('2016-01-14 09:00:00'): 1.08674, Timestamp('2016-01-14 09:15:00'): 1.08671}, 'high': {Timestamp('2016-01-14 08:15:00'): 1.08749, Timestamp('2016-01-14 08:30:00'): 1.08739, Timestamp('2016-01-14 08:45:00'): 1.08734, Timestamp('2016-01-14 09:00:00'): 1.08722, Timestamp('2016-01-14 09:15:00'): 1.08673}, 'low': {Timestamp('2016-01-14 08:15:00'): 1.0869, Timestamp('2016-01-14 08:30:00'): 1.08673, Timestamp('2016-01-14 08:45:00'): 1.08669, Timestamp('2016-01-14 09:00:00'): 1.08666, Timestamp('2016-01-14 09:15:00'): 1.08582}, 'close': {Timestamp('2016-01-14 08:15:00'): 1.08736, Timestamp('2016-01-14 08:30:00'): 1.08673, Timestamp('2016-01-14 08:45:00'): 1.08673, Timestamp('2016-01-14 09:00:00'): 1.08671, Timestamp('2016-01-14 09:15:00'): 1.08618}, 'volume': {Timestamp('2016-01-14 08:15:00'): 2181, Timestamp('2016-01-14 08:30:00'): 1738, Timestamp('2016-01-14 08:45:00'): 1938, Timestamp('2016-01-14 09:00:00'): 3010, Timestamp('2016-01-14 09:15:00'): 2734}}

CodePudding user response:

Well, let's do this!

First things first: enter image description here

  • Related