Python 实现matlab数据绘制
来源:互联网 发布:数据库技术发展 编辑:程序博客网 时间:2024/06/02 07:18
自从使用python脚本后,经常用来调试数据的matlab终于有了一个简单易用的替代方案,相比matlab的.m语言,我更喜欢用python来解决。毕竟没有什么事情是不能python来解决的,如果没有我可以再加一个python来搞定。首先,先亮图,这效果不比matlab差,是吧?
以下代码,来自于项目的工具代码,主要用来绘制log中的数据是否异常,因此直接使用log的输出数据:
11-18 20:45:15.540 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python origin path start 11-18 20:45:15.542 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 1.0 , 0.0 ,0.0 11-18 20:45:15.543 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 1.0 , 1.0 ,0.0 11-18 20:45:15.543 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 1.2 , 2.0 ,0.0 11-18 20:45:15.544 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 1.5 , 2.2 ,0.0 11-18 20:45:15.544 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 2.5 , 2.0 ,0.0 11-18 20:45:15.544 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 3.0 , 2.5 ,0.0 11-18 20:45:15.544 23084-23150/hud.haliai.com.testarway E/HALO+testMovePath: python 3.3 , 3.0 ,0.0
将真保存于文件中,输入指令,满足的格式如下:
python draw_line.py data.txt python start end
其中
data.txt 为数据文件python 为split拆分tag的keywordstart 为起始行标记end 为结束行标记
最后上python代码
import matplotlib.pyplot as pltimport osimport sysimport operatordef getFileVect3(path,filterTag=' ',startTag='start',endTag='end'): print [path,filterTag,startTag,endTag] lineFile = open(path).read().split('\n') print 'lineFile type is '+str(type(lineFile)) oriStart = 0 oriEnd = len(lineFile) number = 0 for line in lineFile: if oriStart==0 and line.find(startTag)!=-1: oriStart=number elif line.find(endTag)!=-1: oriEnd=number number+=1 oriPathX = [] oriPathY = [] oriPathZ = [] indexs = [] for i in range(oriStart+1,oriEnd): raw=lineFile[i] # print 'raw type is '+str(type(raw)) if operator.contains(raw,filterTag): line=raw.split(filterTag) if len(line) != 2: print 'line filter tag error !' head,content = line vect3=content.strip().split(',') if len(vect3) == 3: strX,strY,strZ = vect3 oriPathX.append(float(strX)) oriPathY.append(float(strY)) oriPathZ.append(float(strZ)) indexs.append(float(i)) # print strX,strY,strZ return indexs,oriPathX,oriPathY,oriPathZ# python draw_line.py data.txt split s_tag e_tagif len(sys.argv) != 5: print 'bad para!' exit()cmd,filename,split_tag,start_tag,end_tag=sys.argvprint [filename,split_tag,start_tag,end_tag]i,x,y,z,=getFileVect3('./'+filename,split_tag,start_tag,end_tag)plt.plot(x, y, 'r', label='line 1', linewidth=1.5)plt.ylabel('Test ARWay line convert!')plt.axis('equal')plt.show()
0 0
- Python 实现matlab数据绘制
- Python and Matlab绘制曲线图
- matlab绘制离散数据图
- Matlab编程实现直方图绘制
- python 绘制三维数据
- Python Matplotlib实现三维数据的散点图绘制
- Python Matplotlib实现三维/四维数据的柱状图绘制
- widerface数据库转voc2007数据集(python/matlab实现)
- matlab绘制地理栅格数据示例
- matlab 三个向量数据绘制曲面图
- Matlab 读取数据并绘制图形
- 使用txt文档数据绘制matlab曲线
- python实现matlab功能
- matlab 绘制直方图的函数实现
- [python]使用python实现蜡烛图绘制
- Python实现从excel读取数据并绘制成精美图像
- Python数据和matlab数据转换
- Python/matlab实现KNN算法
- Python进行数据的Join关联操作及从分表取数据一例
- 视频播放(四)
- Maven 的jar包冲突管理
- C语言以邻接矩阵为存储结构的图的构造以及广度优先,深度优先遍历
- 国内一线互联网公司内部面试题库
- Python 实现matlab数据绘制
- 不同数据库中临时表的使用说明
- 屏幕输入法
- 大小堆 排序
- 简单的来谈一谈angular2.0的表单
- Cocos2dx-CCEditBox输入框中英文检测
- 通过easy_install安装egg库遇到的问题
- 蓝桥杯 历届试题 九宫重排
- [Gradle系列]Gradle打包apk多版本,多渠道,多环境,多功能,多模块随心所欲