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


猜你喜欢
- REST framework定义的异常APIException 所有异常的父类ParseError 解析错误AuthenticationFa
- 什么是变量在Python编程语言中,变量是用于存储数据值的标识符。它们可以用来引用数据值,而不是直接使用值本身。可以使用等号(=)运算符来将
- 环境:python3.6 pyqt5只是简单的一个思路,请忽略脆弱的异常防护:# -*- coding: utf-8 -*-import s
- 用python实现简单Server/Client文件传输:服务器端:#!/usr/bin/pythonimport SocketServer
- 最近用python写了一个远程监控的程序,主要功能有:1.用邮件控制所以功能2.可以对屏幕截图,屏幕截图发送到邮箱3.可以用摄像头获取图片,
- 前言python中字符串对象提供了很多方法来操作字符串,功能相当丰富。print(dir(str))[..........'capi
- 完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例。 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机日志
- 本文实例讲述了Python使用MD5加密算法对字符串进行加密操作。分享给大家供大家参考,具体如下:# encoding: utf-8from
- Profile 和 cProfile在 Python 标准库里面有两个模块可以用来做性能测试。1. 一个是 Profile,它是一个纯 Py
- 关于F.normalize计算理解动机最近多次看到该方法出现,于是准备了解一下,搜了后发现原来是所谓的L2 norm计算简介函数定义torc
- 目录注册组件添加组件源代码可拖放文本框允许用户通过拖动备选项至文本框来确定输入,其实也可以说是 combobox 的一种变形。 与 comb
- 1.基数排序基数排序的基本思想是先将数字按照个位数上数字的大小进行排序,排序之后再将已经排过序的数字再按照十位数上数字的大小进行排序,依次推
- 获取所有文章数据o := orm.NewOrm()qs := o.QueryTable("Article")12获取总条
- 做网站数据库,是选SQL Server还是Access好,可能您会说:选MySQL好,不过现在只是讨论IIS+ASP这种架构下的选择,不讨论
- 微软在 Github 上开源了一个 Python 静态类型检查工具:pyright ,引起了社区内的多方关注。微软在开源项目上的参与力度是越
- Pytorch损失函数torch.nn.NLLLoss()在各种深度学习框架中,我们最常用的损失函数就是交叉熵(torch.nn.Cross
- pytorch保存数据pytorch保存数据的格式为.t7文件或者.pth文件,t7文件是沿用torch7中读取模型权重的方式。而pth文件
- 在开始之前还是提一下三个函数吧:"ob_start()、ob_end_clean()、ob_get_contents()"
- 本文实例讲述了Python爬取需要登录的网站实现方法。分享给大家供大家参考,具体如下:import requestsfrom lxml im
- 先以mysql的语句,聚合用在分组里,对mysql中groupby 是分组每什么的时候就要分组,如 每个小组,就按小组分,group by