python 数据可视化 折线图绘制

"""
author:魏振东
data:2019.12.13
func:折线图绘制
"""
import matplotlib.pyplot as plt
# 显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 列表
years=[]
score=[]
# 打开文件
file = open("cj.txt", 'r')
# 把每行的文件读取
linesList = file.readlines()
for line in linesList:
       linesList = line.strip().split(',')
file.close()

# print(linesList)
for x in range(0,8,2):
       years.append(linesList[x])
# print(years)
for y in range(1,8,2):
       score.append(linesList[y])
# print(score)

plt.plot(years, score, 'b*')
plt.plot(years, score, 'r')

plt.xlabel("年级")
plt.ylabel("成绩")

plt.title('年级和成绩')

plt.show()

在这里插入图片描述

发布了39 篇原创文章 · 获赞 41 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wei_zhen_dong/article/details/103586261