一,要读取的数据的格式:
二,数据读取部分:
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)<