excel如何用股价图做数据,excel 股价图怎么做

  

  继续使用证券宝(网址www.baostock.com)接口获取数据   

  

  第一步:导入需要的库   

  

  将matplotlib.pyplot作为pltimport baostock作为资产负债表导入熊猫作为警察局导入日期时间第二步:获取数据   

  

  #选取沪深300code='sh.000300'#开始和结束日期datestart=' 2019-07-01 '今天的日期=日期时间。日期时间。今天.strftime('%Y-%m-%d')#需要显示的列ShowList='date,code,open,high,low,close,preclose,volume,amount,adjustflag,turn,tradestatus,pctChg,isST ' def ListToDf(RS): data _ list=[]while(RS。error _ code==' 0 ')RS。下一个(): #获取一条记录,将记录合并在一起data _ list。追加(RS。get _ row _ data())result=PD .DataFrame(data_list,columns=rs.fields)返回结果####登陆系统####lg=bs.login()#显示登陆返回信息# print('登录响应错误代码: ' LG。error _ code)print(' log in respond error _ msg : ' LG。error _ msg)# #获取沪深A股历史K线数据##### 详细指标参数,参见"历史行情指标参数"章节;"分钟线"参数与"日线"参数不同。# 分钟线指标:日期、时间、代码、开盘、盘高、盘低、收盘、成交量、金额、adjustflagrs=bs。query _ history _ k _ data _ plus(code,ShowList,start_date=datestart,end_date=datetoday,frequency='d ',adjust flag=' 3 ')result=ListToDf(RS)# print(' query _ history _ k _ data _ plus respond error _ code : ' RS .错误代码)打印(' query _ history _ k _ data _ plus respond error _ msg 3: '结果集输出到战斗支援车文件# # # #结果。to _ excel(' history _ A _ stock _ k _ '代码。xls ',index=False)####登出系统# # # #废话。注销()第三步:画图   

  

  #将要画图的列转为漂浮物型结果[' INT _ close ']=结果。关闭。astype(' float ')#以下为画图的基本要素plt.figure()plt.plot结果。日期,结果. INT_close,c='red')ax=plt.gca()#设置标题ax.set_title(code,fontsize=14,color='g')#设置X轴,间隔30plt.xlabel('DATE ',font size=14)ax。xaxis。设置_专业_定位器(PLT .MultipleLocator(30))plt.xlim(0,len(结果))#设置y轴,间隔100plt.ylabel('CLOSE ',font size=14)ax。雅克斯。设置_专业_定位器(PLT .多定位器(100))。ylim(int(0.9 * min(result .INT_close))、int(1.1*max(结果. INT _ close)))第四步:得到图片   

  

  Python股票分析(三)画曲线   

  

  想了解更多Python分析股票方法,敬请请持续关注!   

相关文章