import numpy as npimport matplotlib.pyplot as pltimport matplotlib.mlab as mlabimport matplotlib.cbook as cbookimport matplotlib.ticker as ticker#data file pathwayfileA_path=r'E:\study\python\EBR_data\EBR-from2008.csv'datafile = cbook.get_sample_data(fileA_path,asfileobj = False)print ( 'loading %s' %datafile)r = mlab.csv2rec(datafile)r.sort()#r = r[-30:] # get the last 30 days# first we 'll do it the default way, with gaps on weekendsfig, ax = plt.subplots()ax.plot(r.date, r.adj_close, 'o-')fig.autofmt_xdate()# next we' ll write a custom formatterN = len(r)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 r.date[thisind].strftime('%Y-%m-%d')fig, ax = plt.subplots()ax.plot(ind,r.adj_close,'o-')ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))fig.autofmt_xdate()plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。