【问题标题】:matplotlib candlestick chart bar output error - seems to be plotting more than one timeframe on single barmatplotlib 烛台图柱输出错误 - 似乎在单个柱上绘制了多个时间帧
【发布时间】:2014-08-10 10:14:19
【问题描述】:

我正在尝试使用 matplotlib 绘制带有每小时蜡烛的烛台图。但是我的输出看起来很奇怪,它似乎在一根蜡烛上绘制了多个“小时”。

我的代码如下:

cursor = conx.cursor()
query= 'SELECT ticker,date,time,open,low,high,close FROM eurusd WHERE date > "2014-01-28"'
cursor.execute(query)
for line in cursor:
    #appendLine in correct format for candlesticks - date,open,close,high,low
    date=date2num(line[1])
    open=(line[3])
    high=(line[5])
    low=(line[4])
    close=(line[6])

    appendLine = date,open,close,high,low
    candleAr.append(appendLine)

fig = plt.figure()

ax1 = plt.subplot(1,1,1)

candlestick(ax1, candleAr, width=0.6, colorup='g', colordown='r')

ax1.grid(True)


plt.xlabel('Date')
plt.ylabel('Price')
plt.show()

我的输出如下所示:

我是否必须操纵“date2num”函数来说明我的数据是每小时而不是每天的事实?

【问题讨论】:

    标签: matplotlib candlestick-chart


    【解决方案1】:

    设法回答了我自己的问题 - 这是由于 date2num 输出具有重复值,并且将所有天的小时条都塞进了一个。我必须将我的日期和时间加在一起以获得日期时间,然后在日期时间(而不是日期)上使用 date2num

    date=[]
    open=[]
    low=[]
    high=[]
    close=[]
    candleAr=[]
    
    for line in cursor:
        time1=datetime.time(0,0)
        time=datetime.datetime.combine(line[1],time1)
        time=time+line[2]
        appendLine = date2num(time),line[3],line[6],line[5],line[4]
    

    【讨论】:

      猜你喜欢
      • 2022-11-24
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多