import csv
import matplotlib.pyplot as plt
def readcsv():
file = open("D:/Work/csv/31.csv")
reader = csv.reader(file)
data = []
data1 = []
data2 = []
data3 = []
data4 = []
data5 = []
a = []
# 读取文件数据列
for row in reader:
# column = eval(row[0])
column = row[0]
# min=min(column)
column1 = row[1]
column2 = row[2]
column3 = row[3]
column4 = row[4]
column5 = row[5]
data.append(column)
data1.append(column1)
data2.append(column2)
data3.append(column3)
data4.append(column4)
data5.append(column5)
# 求取第一列的最小值并相减输出
q = min(data)
data = [eval(i) - eval(q) for i in data]
print(data)
# 将数据列重新写入csv文件中
filePath = 'D:/Work/csv/3.csv'
rows = zip(data, data1, data2, data3, data4, data5)
with open(filePath, "w", newline='') as f:
writer = csv.writer(f)
for row in rows:
writer.writerow(row)
def drawpicture():
file = open('D:/Work/csv/31.csv') # 打开csv文件
reader = csv.reader(file) # 读取csv文件
data = list(reader) # 将csv数据转化为列表
length_h = len(data) # 得到数据行数
lenght_l = len(data[0]) # 得到每行长度
x = list()
y = list()
# 绘制散点图
for i in range(0, length_h): # 从第一行开始读取
x.append(float(data[i][0])) # 将第一列数据从第一行读取到最后一行付给列表x
y.append(float(data[i][2])) # 将第三列数据从第一行读取到最后一行付给列表y
# s代表是坐标点的大小,默认为20,c是选择坐标点的颜色,marker是坐标点的形状
plt.scatter(x, y, s=30, c='k', marker='.')
# 将原点放到左上角
#即获得当前图表的图像,对图像进行处理
ax = plt.gca()
#设置坐标轴上的数字显示的位置,top:显示在顶部 bottom:显示在底部,默认是none
ax.xaxis.set_ticks_position('top')
#invert_yaxis()是可以将y轴的顺序进行翻转的
ax.invert_yaxis()
#设置y轴的固定长度
plt.ylim(300)
plt.savefig("1.png")
plt.show()
if __name__ == '__main__':
readcsv()
drawpicture()