av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

python讀取excel數(shù)據(jù)并且畫圖的實(shí)現(xiàn)示例

瀏覽:2日期:2022-06-28 08:48:07
一,要讀取的數(shù)據(jù)的格式:

python讀取excel數(shù)據(jù)并且畫圖的實(shí)現(xiàn)示例

二,數(shù)據(jù)讀取部分:

b站視頻參考:https://www.bilibili.com/video/BV14C4y1W7Nj?t=148

# 1930workbook=xlrd.open_workbook(’1930.xlsx’)sheet= workbook.sheet_by_index(0)A1=[]B1=[]# sheet.cell_value(i,0):第i行的第0個(gè)元素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) 三,畫圖函數(shù)1. def drawBar(Music_genre,singer_num,year)

參數(shù)介紹

參數(shù)名 參數(shù)含義 Music_genre 音樂流派名稱list singer_num 音樂流派對應(yīng)音樂家數(shù)量list year 讀的文件的年份(因?yàn)樵创a是從1840到2020的)

def drawBar(Music_genre,singer_num,year): arr_len=len(Music_genre) # 由循環(huán)得到一個(gè)字典,key是音樂流派,value是這個(gè)音樂流派對應(yīng)的音樂家的數(shù)量 i=0 dict_music_singer={} while i<arr_len: 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:

''' 水平條形圖,需要修改以下屬性 orientation='horizontal''''import numpy as npimport matplotlib.pyplot as plt # 數(shù)據(jù)N = 5x = [20, 10, 30, 25, 15]y = [0,1,2,3,4] # 繪圖 x= 起始位置, bottom= 水平條的底部(左側(cè)), y軸, height 水平條的寬度, width 水平條的長度p1 = plt.bar(x=0, bottom=y, height=0.5, width=x, orientation='horizontal')pyplot.bar(range(arr_len),singer_num,align=’center’)pyplot.bar(x=0, bottom=range(arr_len), height=0.5, width=singer_num, orientation='horizontal')# 展示圖形plt.show()

python讀取excel數(shù)據(jù)并且畫圖的實(shí)現(xiàn)示例

注釋2:plt.xticks的第一個(gè)參數(shù)和plt.plot的第一個(gè)參數(shù)一樣,第二個(gè)參數(shù)是和第一個(gè)參數(shù)相同長度的list此例中用來代替橫坐標(biāo)

import matplotlib.pyplot as pltx = [1, 2, 3, 4]y = [1, 4, 9, 6]labels = [’Frogs’, ’Hogs’, ’Bogs’, ’Slogs’] plt.plot(x, y)# You can specify a rotation for the tick labels in degrees or with keywords.plt.xticks(x, labels, rotation=’vertical’)# Pad margins so that markers don’t get clipped by the axesplt.margins(0.2)# Tweak spacing to prevent clipping of tick-labelsplt.subplots_adjust(bottom=0.15)plt.show()

python讀取excel數(shù)據(jù)并且畫圖的實(shí)現(xiàn)示例

1.1 效果:

python讀取excel數(shù)據(jù)并且畫圖的實(shí)現(xiàn)示例

1.2 完整代碼

import pandas as pdimport numpy as np import xlrdfrom matplotlib import pyplotdef drawBar(Music_genre,singer_num,year): arr_len=len(Music_genre) i=0 dict_music_singer={} while i<arr_len: dict_music_singer[Music_genre[i]]=singer_num[i] i=i+1 #pyplot.bar(range(arr_len),singer_num,align=’center’) pyplot.bar(x=0, bottom=range(arr_len), height=0.3, width=singer_num, orientation='horizontal') pyplot.yticks(range(arr_len),Music_genre) pyplot.title(year) pyplot.show() # 1930workbook=xlrd.open_workbook(’1930.xlsx’)sheet= workbook.sheet_by_index(0)A1=[]B1=[]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) # 1940workbook=xlrd.open_workbook(’1940.xlsx’)sheet= workbook.sheet_by_index(0)A2=[]B2=[]for i in range(1,sheet.nrows): A2.append(sheet.cell_value(i,0)) B2.append(sheet.cell_value(i,1)) if len(A2)!=len(B2): print('False')drawBar(A2,B2,1940) # workbook=xlrd.open_workbook(’1950.xlsx’)sheet= workbook.sheet_by_index(0)A3=[]B3=[]for i in range(1,sheet.nrows): A3.append(sheet.cell_value(i,0)) B3.append(sheet.cell_value(i,1)) if len(A3)!=len(B3): print('False')drawBar(A3,B3,1950) # 6workbook=xlrd.open_workbook(’1960.xlsx’)sheet= workbook.sheet_by_index(0)A4=[]B4=[]for i in range(1,sheet.nrows): A4.append(sheet.cell_value(i,0)) B4.append(sheet.cell_value(i,1)) if len(A4)!=len(B4): print('False')drawBar(A4,B4,1960) # workbook=xlrd.open_workbook(’1970.xlsx’)sheet= workbook.sheet_by_index(0)A5=[]B5=[]for i in range(1,sheet.nrows): A5.append(sheet.cell_value(i,0)) B5.append(sheet.cell_value(i,1)) if len(A5)!=len(B5): print('False')drawBar(A5,B5,1970) # workbook=xlrd.open_workbook(’1980.xlsx’)sheet= workbook.sheet_by_index(0)A6=[]B6=[]for i in range(1,sheet.nrows): A6.append(sheet.cell_value(i,0)) B6.append(sheet.cell_value(i,1)) if len(A6)!=len(B6): print('False')drawBar(A6,B6,1980) # 9workbook=xlrd.open_workbook(’1990.xlsx’)sheet= workbook.sheet_by_index(0)A7=[]B7=[]for i in range(1,sheet.nrows): A7.append(sheet.cell_value(i,0)) B7.append(sheet.cell_value(i,1)) if len(A7)!=len(B7): print('False')drawBar(A7,B7,1990) # 2000workbook=xlrd.open_workbook(’2000.xlsx’)sheet= workbook.sheet_by_index(0)A8=[]B8=[]for i in range(1,sheet.nrows): A8.append(sheet.cell_value(i,0)) B8.append(sheet.cell_value(i,1)) if len(A8)!=len(B8): print('False')drawBar(A8,B8,2000) # workbook=xlrd.open_workbook(’2010.xlsx’)sheet= workbook.sheet_by_index(0)A9=[]B9=[]for i in range(1,sheet.nrows): A9.append(sheet.cell_value(i,0)) B9.append(sheet.cell_value(i,1)) if len(A9)!=len(B9): print('False')drawBar(A9,B9,2010) # # # workbook=xlrd.open_workbook(’2020.xlsx’)# sheet= workbook.sheet_by_index(0)# A2=[]# B2=[]# for i in range(1,sheet.nrows):# A2.append(sheet.cell_value(i,0))# B2.append(sheet.cell_value(i,1)) # if len(A2)!=len(B2):# print('False')# drawBar(A2,B2,2020)

以上就是python讀取excel數(shù)據(jù)并且畫圖的實(shí)現(xiàn)示例的詳細(xì)內(nèi)容,更多關(guān)于python讀取excel數(shù)據(jù)并且畫圖的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: python
相關(guān)文章:
主站蜘蛛池模板: 日韩免费网站 | 国产精品久久久久久吹潮 | 欧美日韩在线一区二区 | 精品在线一区二区三区 | 9999视频| www.99热这里只有精品 | 性色av香蕉一区二区 | 国产成人免费视频 | 国产精品日韩在线观看一区二区 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 欧美13videosex性极品 | 日韩中文一区二区三区 | 亚洲国产精品久久久久婷婷老年 | 亚洲欧洲激情 | 亚洲精品国产第一综合99久久 | 亚洲综合色丁香婷婷六月图片 | 国产一级淫片a直接免费看 免费a网站 | 红桃视频一区二区三区免费 | 亚洲欧美在线免费观看 | 亚洲人在线 | 欧美三级网站 | 精品亚洲一区二区 | 欧美日韩亚 | 在线国产中文字幕 | 综合国产第二页 | 国产精品一区免费 | 福利视频网站 | 国产在线不卡视频 | 一本一道久久a久久精品综合蜜臀 | 欧美在线视频网站 | 国产成人精品久久二区二区91 | 久久6| 欧美福利视频一区 | 黄色一级毛片免费看 | 国产一区二区三区四区在线观看 | 午夜私人影院在线观看 | 亚洲一区二区三区免费视频 | 午夜电影福利 | 日韩久久久久久久久久久 | 91视频在线观看 | 成人免费区一区二区三区 |