日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python如何实现matlab_Python实现matlab数据绘制

發(fā)布時(shí)間:2024/1/23 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何实现matlab_Python实现matlab数据绘制 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

自從使用python腳本后,經(jīng)常用來調(diào)試數(shù)據(jù)的matlab終于有了一個(gè)簡(jiǎn)單易用的替代方案,相比matlab的.m語言,我更喜歡用python來解決。畢竟在python當(dāng)中,相比.m主意很多編程工作都可以輕而易舉地完成。

首先,先亮圖,這效果不比matlab差,是吧?

繪制曲線

一、例程

1、測(cè)試環(huán)境

import matplotlib.pyplot as plt

上面代碼不能正常使用時(shí),說明并未安裝模塊需要執(zhí)行

pip install matplotlib

2、要顯示的數(shù)據(jù)

以下代碼,來自于項(xiàng)目的工具代碼,主要用來繪制log中的數(shù)據(jù)是否異常,因此直接使用log的輸出數(shù)據(jù):

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

3、python 實(shí)現(xiàn)代碼

import matplotlib.pyplot as plt

import os

import sys

import operator

def 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_tag

if len(sys.argv) != 5:

print 'bad para!'

exit()

cmd,filename,split_tag,start_tag,end_tag=sys.argv

print [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()

4、使用方式

將真保存于文件中,輸入指令,滿足的格式如下:

python draw_line.py data.txt python start end

其中

data.txt 為數(shù)據(jù)文件

python 為split拆分tag的keyword

start 為起始行標(biāo)記

end 為結(jié)束行標(biāo)記

總結(jié)

以上是生活随笔為你收集整理的python如何实现matlab_Python实现matlab数据绘制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。