python读取excel并绘图

python读取excel并绘图的代码

import openpyxl
import matplotlib.pyplot as plt

wb = openpyxl.load_workbook('渗透记录表(1).xlsx')  # 载入excel工作簿
a = wb.get_sheet_names()  # 获取工作簿中所有工作表的名字
st = wb.get_sheet_by_name('Sheet1')  # 获取某张工作表的内容
d = st['B1'].value  # 获取某个单元格的值

rows = st.max_row  # 获取行数
cols = st.max_column  # 获取列数

e = st['C1'].column

# print(e)

# # 对行进行遍历,输出A1,B1,C1
# for row in st.rows:
#     for cell in row:
#         print(cell.value)
#
# # 对列进行遍历,输出A1,A2,A3
# for column in st.columns:
#     for cell in column:
#         print(cell.value)
# 对某一特定的行进行遍历
# for cell in list(st.rows)[1]:
#     print(cell.value)
# 对某一特定的列进行遍历
# for cell in list(st.columns)[1]:
#     print(cell.value)

# 对某一单元格范围进行遍历
# for spaces in st['B2':'B11']:
#     for cell in spaces:
#         print(cell.value)

y = list()
x = list()
for spaces in st['B2':'B11']:
    for cell in spaces:
        y.append(int(cell.value))

for spaces in st['A2':'A11']:
    for cell in spaces:
        x.append(cell.value)

plt.plot(x, y)

plt.xticks(x, color='green', rotation=60)  # 改变x轴标签的颜色和倾斜角度

plt.show()

在这里插入图片描述

  • 4
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值