python 读取目录下csv文件并绘制曲线v111的方法
作者:liang890319 发布时间:2022-08-21 16:05:34
标签:python,csv,曲线
实例如下:
# -*- coding: utf-8 -*-
"""
Spyder Editor
This 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 y
V1.1.1 get all filenames in shortout dir choose one to analysis
"""
# coding: utf-8
import time
import string
import os
import math
import pylab
import csv
import numpy as np
from numpy import genfromtxt
import matplotlib
import matplotlib as mpl
from matplotlib.colors import LogNorm
from matplotlib.mlab import bivariate_normal
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.animation as animation
pause = False
linenum=0
fileList=[] #待处理文件路径
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()
##如果是参数是list,则默认每次取list中的一个元素,即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 鼠标左键按下 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') # 关闭图 0
来源:https://blog.csdn.net/liang890319/article/details/52082749
0
投稿
猜你喜欢
- 以下为引用的内容: <html> <head> <title>不刷新页面查询的方法&
- 本文实例讲述了Python3读取文件常用方法。分享给大家供大家参考。具体如下:''''' Creat
- 以前的Dreamweaver中是没有图片处理功能的,即使你要处理也只能使用CSS中的相关滤镜进行一些效
- 下面列出了asp远程网页数据采集程序中经常用到的函数,很实用,特别是正则表达式过滤函数。包括了使用xmlhttp采集远程网页内容,使用ado
- key_buffer_size - 这对MyISAM表来说非常重要。如果只是使用MyISAM表,可以把它设置为可用内存的 30-40%。合理
- 1、新建DLL打开VB6-->文件-->新建工程-->选择ActiveX DLL-->确定2、将默认工程、类重命名工
- <?php// 使用Memache 作为进程锁 class lock_processlock{// key 的前缀protected
- 本人最近在学习python,在看了一些教程后,用python写了一个简单的云音乐播放器,下面把主要代码贴上来,其中用到了github上他人写
- 函数重载的替代方法-伪重载,下面看一个具体的实例代码。<? php//函数重载的替代方法-伪重载////确实,在PHP中没有函数重载这
- 在网站的一些应用中需要提供用户直接打印页面的功能,最明显的就是电子优惠券,商家根据网站提供的模板输入内容,然后生成优惠券页面,用户打印这个页
- 这个问题困扰了我很长很长的时间,在跨域获取数据的时候就要用到服务器端的对象,以前一直用的是Msxml.XMLHTTP。但是问题太多了,特别严
- 在我发表上一篇《Zen Coding: 一种快速编写HTML/CSS代码的方法》之后,有网友表示不知道怎么在Dreamweaver上使用ze
- show.php源代码: <? if ($action=="cp"){ echo"<div ali
- 见下表:序号保留字序号保留字序号保留字1ADD80ESCAPE159OR2ABSOLUTE81EXCEPT160ORDER3ACTION82
- python ThreadPoolExecutor线程池的工作线程中出现异常时,主线程不会捕获异常。解决方法1:直接在需要执行的任务方法中添
- 首先来看一个封装的curl函数function request_post($url = '', $param = '
- 1、查找表结构,判断要加入的列是否已存在2、如果不存在,则执行添加 CREATE PROCEDURE `mysql_sp_add_
- 本文实例讲述了PHP函数extension_loaded()用法。分享给大家供大家参考。具体分析如下:extension_loaded —
- 今天在给一个img加链接时发现的<body> <a href="#1" >&
- 概述基于Swoole的websocket服务,计划整合3篇进行技术整理,该服务主要有2个核心业务,用户消息服务(消息计数统计)和 客服IM消