import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['KaiTi'] with open(r'E:\pythoncoda\read\notebook.txt', encoding='utf-8') as file: # contents = file.read() # print(contents) # 逐行输出,需要把上面两行注释掉,否则不能输出 # for line in file: # print('line:', line) # 第二种成行输出方法 contents = file.readlines() print(contents) newList = [] for content in contents: newContent = content.replace('\n', '') money = newContent.split(':')[-1] newList.append(int(money)) print(newList) x = [1, 2, 3, 4, 5, 6] y = newList plot = plt.plot(x, y, 'r', label='销售') plt.xlabel('month') plt.ylabel('money') plt.savefig('销售额.png') plt.legend() plt.show() # 求平均值 sum0 = 0 for money in newList: sum0 += money average = sum0 / len(newList) print("average:", average) average
‘UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x80 in position 2: illegal multibyte sequence’
于 2022-05-06 12:19:03 首次发布