from __future__ import print_functionimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.mlab as mlabimport matplotlib.cbook as cbookimport matplotlib.ticker as tickerimport datetimeimport matplotlib.finance as financetickerA = 'EBR'begdate = datetime.date(2000,1,1)enddate = datetime.date.today()priceA = finance.fetch_historical_yahoo(tickerA, begdate, enddate)rA = mlab.csv2rec(priceA); priceA.close()rA.sort()#r = r[-30:] # get the last 30 daysfigA, axA = plt.subplots()axA.plot(rA.date, rA.adj_close, 'o-')#ax.set_title('Fig. 1: EBR last 30 days with gaps on weekends')figA.autofmt_xdate()N = len(rA)ind = np.arange(N) # the evenly spaced plot indicesdef format_date(x, pos=None):thisind = np.clip(int(x+0.5), 0, N-1)return rA.date[thisind].strftime('%Y-%m-%d')figA, axA = plt.subplots()axA.plot(ind, rA.adj_close, 'o-')plt.xlabel("Every Monday shown")axA.set_title('Fig 2: IBM last 30 days evenly spaced plot indices')axA.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))figA.autofmt_xdate()plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。