0
plt.rc('axes', grid=True)
plt.rc('grid', color='0.75', linestyle='-', linewidth=0.5)

textsize = 9
left, width = 0.1, 0.8
rect1 = [left, 0.7, width, 0.2]

fig = plt.figure(facecolor='white')
axescolor  = '#f6f6f6'  # the axes background color

ax1 = fig.add_axes(rect1, axisbg=axescolor)  #left, bottom, width, height

### plot the relative strength indicator

rsi = RSI(GOOG,20) #rsi[0] is list of float, rsi[1] is list of datetime objects
rsiValues = rsi[0]
rsiDate = rsi[1]
ticker = 'GOOG'
fillcolor = 'darkgoldenrod'

ax1.plot(rsiDate, rsiValues, 'kx') #, fmt='bo', tz=None, xdate=True, ydate=False,color=fillcolor)
ax1.axhline(70, color=fillcolor)
ax1.axhline(30, color=fillcolor)
#ax1.fill_between(rsiDate, rsiValues, 70, where=(rsiValues>=70),facecolor=fillcolor,   edgecolor=fillcolor)
#ax1.fill_between(rsiDate, rsiValues, 30, where=(rsiValues<=30), facecolor=fillcolor, edgecolor=fillcolor)
ax1.text(0.6, 0.9, '>70 = overbought', va='top', transform=ax1.transAxes, fontsize=textsize)
ax1.text(0.6, 0.1, '<30 = oversold', transform=ax1.transAxes, fontsize=textsize)
ax1.set_ylim(0, 100)
ax1.set_yticks([30,70])
ax1.set_xticks(rsiDate,minor = True)

#just want day date
tickLabels = []
for items in rsiDate:
    tickLabels.append(items.day) 

ax1.set_xticklabels(tickLabels, rotation = 45,minor = True)
ax1.text(0.025, 0.95, 'RSI (20)', va='top', transform=ax1.transAxes, fontsize=textsize)
ax1.set_title('%s daily'%ticker)

plt.show()

如果我注释掉“minor = True”

ax1.set_xticklabels(tickLabels, rotation = 45)#,minor = True)

主要刻度标签的日期正确显示(仅显示日期),但如果我取消注释(原样)所有刻度标签显示,但在主要刻度上添加了“月-日-年”标签。我试图在没有任何“月-日-年”标签的情况下仅获取所有刻度(包括次要刻度)的日期。

4

1 回答 1

0
ax1.tick_params(which='major', axis = 'x', labelbottom = 'off')

添加这行代码有效。

于 2013-03-01T23:07:43.647 回答