python 读取目录下csv文件并绘制曲线v111的方法
实例如下:
#-*-coding:utf-8-*- """ SpyderEditor Thistemporaryscriptfileislocatedhere: C:\Users\user\.spyder2\.temp.py """ """ Showhowtomodifythecoordinateformattertoreporttheimage"z" valueofthenearestpixelgivenxandy V1.1.1getallfilenamesinshortoutdirchooseonetoanalysis """ #coding:utf-8 importtime importstring importos importmath importpylab importcsv importnumpyasnp fromnumpyimportgenfromtxt importmatplotlib importmatplotlibasmpl frommatplotlib.colorsimportLogNorm frommatplotlib.mlabimportbivariate_normal importmatplotlib.pyplotasplt importmatplotlib.cmascm importmatplotlib.animationasanimation pause=False linenum=0 fileList=[]#待处理文件路径 forfilenameinos.listdir(r'D:\shortout'): pa='D:\shortout\%s'%filename fileList.append(pa) #forfilesinrange(0,len(fileList)): metric=genfromtxt(fileList[0],delimiter=',') lines=len(metric) #printlen(metric) #printlen(metric[4]) #printmetric[4] rowdatas=metric[:,0] forindexinrange(len(metric[4])-1): a=metric[:,index+1] rowdatas=np.row_stack((rowdatas,a)) #printlen(rowdatas) #printlen(rowdatas[4]) #printrowdatas[4] # #plt.figure(figsize=(38,38),dpi=80) #plt.plot(rowdatas[4]) #plt.xlabel('time') #plt.ylabel('value') #plt.title("USBHIDdataanalysis") #plt.show() ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],... listdata=rowdatas.tolist() printlistdata[4] #fig=plt.figure() #window=fig.add_subplot(111) #line,=window.plot(listdata[4]) #plt.ion() #fig,ax=plt.subplots() #line,=ax.plot(listdata[4],lw=2) #ax.grid() fig=plt.figure() ax=fig.add_subplot(111) line,=ax.plot(listdata[4],lw=2)#I'mstillnotclearonthisstucture... ax.grid() time_template='DataROW=%d' time_text=ax.text(0.05,0.9,'',transform=ax.transAxes) #ax=plt.axes(xlim=(0,700),ylim=(0,255)) #line,=ax.plot([],[],lw=2) defonClick(event): globalpause pause^=True print'userclickthemouse!' print'youpressed',event.button,event.xdata,event.ydata #event.button=1鼠标左键按下2中键按下3右键按下 defgetData(): globallistdata globallinenum t=0 whilet以上这篇python读取目录下csv文件并绘制曲线v111的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。