将Excel第一列数据按空格拆分开,同时提取自己想要的列,生成图像
import numpy as np
import matplotlib.pyplot as plt
import xlrd
file_location = "2.xlsx"
#从本地地址读取xlsx文件#
data = xlrd.open_workbook(file_location)
#打开excel第几张表
table = data.sheet_by_index(0)
#获取总行数
rows = table.nrows
# 获取总列数
cols = table.ncols
cell_data_list = []
data = []
for i in range(rows):
cell = table.cell_value(i, 0)
cell_split=cell.split( )
cell_data=float(cell_split[len(cell_split)-1])
cell_data_list.append(cell_data)
a = list(range(2,141,7))
for j in range(len(a)):
data.append(cell_data_list[a[j]])
print(data)
x1 = np.linspace(1, 96, 20)
y1 = data
#y轴范围
plt.ylim(0, 1)
#x轴范围
plt.xlim(1, 96)
#每个轴的名称
plt.ylabel("Accuracy", fontsize=10)
plt.xlabel("Epoch", fontsize=10)
plt.plot(x1, y1)
plt.show()