引入需要的函数库
import matplotlib.pyplot as plt
import csv
对csv文件的读取操作:实现行读取
path="csv文件地址"
with open(path) as data:
reader = csv.reader(data)
rows = [row for row in reader]
print(rows[0])
对csv文件的读取操作:实现列读取
with open(path) as data2:
reader = csv.reader(data2)
column = [row[0] for row in reader]
print(column)
图表中文处理
plt.rcParams['font.sans-serif'] = ['SimHei']
x轴和y轴分别需要两个列表传入数据
x_data = [1, 2, 3, 4, 5]
y_data = [1, 2, 3, 4, 5]
制图
plt.plot(x_data, y_data, 'ro-', alpha=0.8, linewidth=1, label='图例内容')
plt.legend(loc="upper left")
绘制x轴与y轴
plt.xlabel('x轴名称')
plt.ylabel('y轴名称')
显示与保存
plt.show()
plt.savefig('demo.jpg')