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

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章