国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 讀取目錄下csv文件并繪制曲線v111的方法

2020-02-15 22:12:06
字體:
供稿:網(wǎng)友

實(shí)例如下:

# -*- coding: utf-8 -*-"""Spyder EditorThis temporary script file is located here:C:/Users/user/.spyder2/.temp.py""""""Show how to modify the coordinate formatter to report the image "z"value of the nearest pixel given x and yV1.1.1 get all filenames in shortout dir choose one to analysis"""# coding: utf-8 import timeimport stringimport os import math import pylabimport csv import numpy as npfrom numpy import genfromtxtimport matplotlibimport matplotlib as mplfrom matplotlib.colors import LogNormfrom matplotlib.mlab import bivariate_normal import matplotlib.pyplot as pltimport matplotlib.cm as cm  import matplotlib.animation as animation   pause = Falselinenum=0fileList=[]  #待處理文件路徑for filename in os.listdir(r'D:/shortout'): pa='D:/shortout/%s'%filename fileList.append(pa) #for files in range(0,len(fileList)): metric = genfromtxt(fileList[0], delimiter=',')lines=len(metric) #print len(metric)#print len(metric[4])#print metric[4]  rowdatas=metric[:,0]for index in range(len(metric[4])-1): a=metric[:,index+1] rowdatas=np.row_stack((rowdatas,a)) #print len(rowdatas)#print len(rowdatas[4])#print rowdatas[4] #  #plt.figure(figsize=(38,38), dpi=80)#plt.plot(rowdatas[4] )#plt.xlabel('time')#plt.ylabel('value')#plt.title("USBHID data analysis")#plt.show()  ##如果是參數(shù)是list,則默認(rèn)每次取list中的一個(gè)元素,即metric[0],metric[1],... listdata=rowdatas.tolist()print listdata[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'm still not clear on this stucture...ax.grid() time_template = 'Data ROW = %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) def onClick(event): global pause pause ^= True print 'user click the mouse!' print 'you pressed', event.button, event.xdata, event.ydata# event.button=1 鼠標(biāo)左鍵按下 2 中鍵按下 3 右鍵按下   def getData():  global listdata global linenum t = 0  while t < len(listdata[4]):  if not pause:    linenum=linenum+1  yield listdata[linenum-1]# while t < len(listdata[4]): #  t = t + 1 #  print t,t#  yield t, t   def update(data):  global linenum line.set_ydata(data)  time_text.set_text(time_template % (linenum)) return line,  def init():# ax.set_ylim(0, 1.1)# ax.set_xlim(0, 10)# line.set_data(xdata) plt.xlabel('time') plt.ylabel('Time') plt.title('USBHID Data analysis') return line,fig.canvas.mpl_connect('button_press_event', onClick) ani = animation.FuncAnimation(fig, update , getData , blit=False, interval=1*1000,init_func=init,repeat=False) plt.show()   #my_data = genfromtxt('D:/export.csv', delimiter=',')#rgbdata=my_data、255#plt.figure(figsize=(38,38), dpi=80)##for index in range(3):# row9=rgbdata[:,index]# print "row %d size is/n"%(index)# plt.plot(row9 )# plt.xlabel('time')# plt.ylabel('value')# plt.title("USBHID data analysis")# plt.legend()## plt.cla()## plt.clf()#plt.show()#plt.figure(1)#plt.imshow(rgbdata, interpolation='nearest')#plt.grid(True) #fig = plt.figure() # 新圖 0#plt.savefig() # 保存#plt.close('all') # 關(guān)閉圖 0             
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 温宿县| 达尔| 余干县| 吉首市| 海晏县| 陇南市| 二连浩特市| 铜山县| 张家口市| 苗栗市| 界首市| 林口县| 广汉市| 芦溪县| 稻城县| 保定市| 景德镇市| 黄梅县| 安仁县| 元谋县| 武定县| 广水市| 枣强县| 忻城县| 绵竹市| 玛多县| 宾川县| 四子王旗| 弥勒县| 军事| 古丈县| 思茅市| 碌曲县| 九寨沟县| 定远县| 赤城县| 云龙县| 阿拉善左旗| 三都| 通州市| 西乡县|