标签:pen lin txt core 数据 使用 label tle size
测试使用python的matplotlib 将数据图形化。测试脚本:
#!/usr/bin/env python3
import os
import matplotlib.pyplot as plt
x = []
y = []
fp = open("score.txt",‘r‘)
data = fp.readlines()
for i in data:
tempx = (i.split())[0]
tempy = (i.split())[1]
x.append(tempx)
y.append(int(tempy))
fp.close()
plt.ylim(1, 100)
plt.title("Exam Score", fontsize=24)
plt.xlabel("Name", fontsize=14)
plt.ylabel("Score", fontsize=14)
plt.plot(x, y)
plt.show()
score.txt文件内容
BJ:pro-test $ cat score.txt
shi001 77
wangzeng002 90
ji003 83
wanting004 98
xu005 90
li006 80
jing007 76
wangbao008 66
wangshi009 84
denghao 78
效果图:
整理如下:
#!/usr/bin/env python3
import os
import sys
import matplotlib.pyplot as plt
resultfile = sys.argv[1]
x = []
y = []
def get_garph():
fp = open(resultfile,‘r‘)
data = fp.readlines()
for i in data:
tempx = (i.split())[0]
tempy = (i.split())[1]
x.append(tempx)
y.append(int(tempy))
fp.close()
plt.ylim(1, 100)
plt.title("Exam Score-2020", fontsize=24)
plt.xlabel("Name", fontsize=14)
plt.ylabel("Score", fontsize=14)
plt.plot(x, y)
plt.show()
return
if __name__ == ‘__main__‘:
get_garph()
脚本执行:
python3 data_graph2.py "venv3/score.txt"
标签:pen lin txt core 数据 使用 label tle size
原文地址:https://blog.51cto.com/magic3/2506675