赞
踩
- import xlrd
- from pylab import *
- mpl.rcParams['font.sans-serif'] = ['SimHei'] # 添加这条可以让图形显示中文
- x_axis_data = linspace(0, 0.9, 10)
- path = '缺失数据.xlsx'
- labels = ['BTD-GTAN', 'GTAN','STGCN','ASTGCN','DCRNN','DSANET','STSGCN']
- colors=['red', 'orange', 'hotpink', 'blue', 'purple', 'black', 'green']
- fmt=[".", "^", "v", "<", "*", ">", "s"]
-
-
- data_excel = xlrd.open_workbook(path)
-
-
- """ 获取所有sheet名称 """
- sheet_names = data_excel.sheet_names()
- print(sheet_names)
-
- # 通过name获取第一个sheet对象
- sheet1_object = data_excel.sheet_by_name(sheet_name="Sheet1")
- print(sheet1_object) # 结果:<xlrd.sheet.Sheet object at 0x0000000002956710>
-
- """ 获取所有或某个sheet对象 """
- sheets_object = data_excel.sheets()
- print(sheets_object)
-
- """ 判断某个sheet 是否已导入"""
- sheet_is_load = data_excel.sheet_loaded(sheet_name_or_index=0)
- print(sheet_is_load)
-
- """ 对sheet对象中的行执行操作 """
- ncols = sheet1_object.ncols
- print(ncols)
-
- # 获取sheet1中列的数据
- for i in range(ncols):
- col_values = sheet1_object.col_values(colx=i)
- plt.plot(x_axis_data, col_values[1:11], marker=fmt[i], color=colors[i], label=col_values[0])
- print(i)
- print(col_values)
-
-
- # 获取sheet1中行的数据类似
-
-
- plt.xlabel('Missing rate')
- plt.ylabel('MAE')
- # 添加图例
- plt.legend()
-
- plt.savefig("fig8.pdf", dpi=600, format="pdf")
-
- plt.show()
-
-
-
- # plot中参数的含义分别是横轴值,纵轴值,线的形状,颜色,透明度,线的宽度和标签
- # plt.plot(x_axis_data, y_data[1:11], 'ro-', alpha=0.8, linewidth=1, label='BTD-GTAN')
-
-
- # 显示标签,如果不加这句,即使在plot中加了label='一些数字'的参数,最终还是不会显示标签
-
-
- # plt.show()
- # plt.savefig('demo.jpg') # 保存该图片
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。