数据可视化——matplotlib绘制组合图

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部分数据如下:
在这里插入图片描述
运行结果如下:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值