python处理csv数据动态显示曲线实例代码
作者:liang890319 时间:2022-05-01 00:35:05
本文研究的主要是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
"""
# coding: utf-8
import time
import string
import os
import math
import pylab
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
metric = genfromtxt('D:\export.csv', 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()
linenum=1
##如果是参数是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] )
fig, ax = plt.subplots()
line, = ax.plot(listdata[4],lw=2)
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 update(data):
global linenum
line.set_ydata(data)
# print 'this is line: %d'%linenum
time_text.set_text(time_template % (linenum))
linenum=linenum+1
# nextitem = input(u'输入任意字符继续: ')
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,
ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)
plt.show()
来源:http://blog.csdn.net/liang890319/article/details/52062905
标签:python,csv
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈Python的条件判断语句if/else语句
2021-03-06 12:11:02
VBScript GetObject 函数用法介绍
2008-01-30 17:00:00
使用django实现一个代码发布系统
2022-06-28 02:42:45
![](https://img.aspxhome.com/file/2023/4/65114_0s.png)
python使用电子邮件模块smtplib的方法
2023-09-29 20:20:38
![](https://img.aspxhome.com/file/2023/3/63203_0s.jpg)
FCKeditor 编辑器实战技巧 Ⅰ
2008-10-08 10:22:00
![](https://img.aspxhome.com/file/uploadpic/20071/200713110656772.gif)
Python制作CSDN免积分下载器
2021-12-25 03:46:35
![](https://img.aspxhome.com/file/2023/5/71385_0s.jpg)
PHP原型模式Prototype Pattern的使用介绍
2023-05-25 01:21:04
浅谈python新手中常见的疑惑及解答
2022-06-23 18:45:40
网页中常用数字/字母序号与代码对照表
2009-03-19 14:00:00
Oracle7.X 回滚表空间数据文件误删除处理方法
2010-07-28 12:54:00
Python中使用Frozenset对象的案例详解
2023-09-27 09:36:32
通过事务日志解决SQL Server常见四大故障(一)
2009-03-25 13:46:00
python实现五子棋游戏(pygame版)
2021-09-15 16:01:42
![](https://img.aspxhome.com/file/2023/6/65916_0s.gif)
Python如何使用Gitlab API实现批量的合并分支
2023-01-31 18:17:45
详解opencv中画圆circle函数和椭圆ellipse函数
2023-08-10 22:11:40
![](https://img.aspxhome.com/file/2023/9/64679_0s.png)
SQL中JOIN和UNION区别、用法及示例介绍
2012-08-21 10:47:22
php进程daemon化的正确实现方法
2023-10-01 09:14:09
双屏显示提升前端开发10%工作效率
2009-03-16 18:22:00
![](https://img.aspxhome.com/file/UploadPic/20093/16/screen-34s.jpg)
边框样式的写法总结
2009-01-18 13:00:00
sp_executesql 使用复杂的Unicode 表达式错误的解决方法
2012-01-29 17:58:52