import xlrd
import matplotlib.pyplot as plt
book = xlrd.open_workbook('test.xlsx')
sheet = book.sheet_by_name('Sheet1')
# fig表示figure窗体, ax表示axes绘图区
fig, ax = plt.subplots(7,1,figsize=(5,10))
for i in range(7):
# 绘图
ax[i].plot(sheet.col_values(0)[1:], sheet.col_values(i+1)[1:], 'r', label = 'type1')
ax[i].plot(sheet.col_values(0)[1:], sheet.col_values(i+8)[1:], 'b', label = 'type2')
# 设置边框颜色
ax[i].spines['top'].set_color('white')
ax[i].spines['right'].set_color('white')
if i < 6:
# 设置边框颜色
ax[i].spines['bottom'].set_color('white')
# 设置刻度线和刻度值个数
ax[i].set_xticks([])
if i == 0:
# 添加图例
ax[i].legend(loc='lower right')
# 设置刻度值用科学记数法,axis可以是'x'、'y'和'both'
ax[i].ticklabel_format(style='sci', scilimits=(-1,2), axis='both')
# 自动调节子图间距
plt.tight_layout()
# 保存图像
plt.savefig('test.png')
plt.show()
test.xlsx部分数据如下:
运行结果如下: