Python 烛台日期索引格式化程序

Python 烛台日期索引格式化程序,python,graph,matplotlib,Python,Graph,Matplotlib,在使用matplotlib绘制股票数据时,我想消除周末之间的“间隙”。我能够做到这一点,结果是下图: 现在,当我尝试在x轴上运行索引格式化程序时,得到的只是一个空白画布。有人知道我做错了什么吗?如果我注释掉FuncFormatter行,所有内容都会再次工作 #Build parameters for candlestick graph. Adjust dates so that they are graphed equi-distant on chart x = 0 y = len(date)

在使用matplotlib绘制股票数据时,我想消除周末之间的“间隙”。我能够做到这一点,结果是下图:

现在,当我尝试在x轴上运行索引格式化程序时,得到的只是一个空白画布。有人知道我做错了什么吗?如果我注释掉
FuncFormatter
行,所有内容都会再次工作

#Build parameters for candlestick graph. Adjust dates so that they are graphed equi-distant on chart
x = 0
y = len(date)
ind = np.arange(y)

candleAr = []
while x < y:
    appendLine = ind[x], openp[x], closep[x], highp[x], lowp[x], volume[x]
    candleAr.append(appendLine)
    x+=1

def format_date(x, pos=None):
    thisind = np.clip(int(x+0.5), 0, y-1)
    return candleAr.date[thisind].strftime('%Y-%m-%d')

#Define plot area and candlestick chart
fig = plt.figure(facecolor='w')
ax1 = plt.subplot2grid((1,1), (0,0), axisbg='w')
candlestick(ax1, candleAr, width=0.8, colorup='#9eff15', colordown='#ff1717')
ax1.xaxis.set_major_formatter(mticker.FuncFormatter(format_date))
fig.autofmt_xdate()
plt.show()
#为烛台图构建参数。调整日期,使其在图表上等距绘制
x=0
y=len(日期)
ind=np.arange(y)
烛光=[]
当x
对于任何感兴趣的人,下面是我如何编写
格式\u日期
函数来实现此功能:

def format_date(x, pos=None):
        newdate = mdates.num2date(date[int(x)])

        if newdate.strftime('%m') == '02':
            return newdate.strftime('%b\n%Y')
        else: return newdate.strftime('%b')