Python matplotlib可视化图形
2021-05-07 19:27
标签:pen lin txt core 数据 使用 label tle size 测试脚本: score.txt文件内容 效果图: 整理如下: 脚本执行: Python matplotlib可视化图形 标签:pen lin txt core 数据 使用 label tle size 原文地址:https://blog.51cto.com/magic3/2506675#!/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()
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"
上一篇:django项目之api验证部分
下一篇:SM3哈希算法
文章标题:Python matplotlib可视化图形
文章链接:http://soscw.com/index.php/essay/83802.html