python读excel中数据画图_python读取excel数据并且画图的实现示例

一,要读取的数据的格式:

ef283454ab8c44bfc260d23d0fc95cfe.png

二,数据读取部分:

b站视频参考:https://www.bilibili.com/video/BV14C4y1W7Nj?t=148

# 1930

workbook=xlrd.open_workbook('1930.xlsx')

sheet= workbook.sheet_by_index(0)

A1=[]

B1=[]

# sheet.cell_value(i,0):第i行的第0个元素

for i in range(1,sheet.nrows):

A1.append(sheet.cell_value(i,0))

B1.append(sheet.cell_value(i,1))

if len(A1)!=len(B1):

print("False")

drawBar(A1,B1,1930)

三,画图函数

1. def drawBar(Music_genre,singer_num,year)

参数介绍

参数名

参数含义

Music_genre

音乐流派名称list

singer_num

音乐流派对应音乐家数量list

year

读的文件的年份(因为源代码是从1840到2020的)

def drawBar(Music_genre,singer_num,year):

arr_len=len(Music_genre)

# 由循环得到一个字典,key是音乐流派,value是这个音乐流派对应的音乐家的数量

i=0

dict_music_singer={}

while i

dict_music_singer[Music_genre[i]]=singer_num[i]

i=i+1

# 注释1

pyplot.bar(x=0, bottom=range(arr_len), height=0.3, width=singer_num, orientation="horizontal")

# 注释2

pyplot.yticks(range(arr_len),Music_genre)

# 加title,展示图像

pyplot.title(year)

pyplot.show()

...

...

drawBar(A1,B1,1930

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值