欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實(shí)現(xiàn)從文件中讀取數(shù)據(jù)并繪制成 x y 軸圖形的方法

 更新時(shí)間:2018年10月14日 11:02:04   作者:流風(fēng)回雪1963  
今天小編就為大家分享一篇python實(shí)現(xiàn)從文件中讀取數(shù)據(jù)并繪制成 x y 軸圖形的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

如下所示:

import matplotlib.pyplot as plt
import numpy as np


def readfile(filename):
 dataList = []
 dataNum = 0
 with open(filename,'r') as f: 
  for line in f.readlines(): 
   linestr = line.strip('\n')
   if len(linestr) < 8 and len(linestr) >1:
    dataList.append(float(linestr))
    dataNum += 1
 return dataList, dataNum
   
    
y, range = readfile("./session.log") 
# print y
print "range=%d" % (range)   
x = np.linspace(0, 1, range)
# plt.plot(x, y, 'r-o')
plt.plot(x, y)
plt.show()

數(shù)據(jù)格式:

0.8960
0.9456
0.9069
0.9128
0.9306
1.0186
1.0327
0.9835
0.9438
0.9807
0.9949
1.0737
1.0842
1.0445
1.0609
1.0664
0.9748
1.0427
1.0983
1.0814
1.1083
1.1051

圖形:

python 讀取數(shù)據(jù)并繪制成 x y 軸圖形

以上這篇python實(shí)現(xiàn)從文件中讀取數(shù)據(jù)并繪制成 x y 軸圖形的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論