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

二,数据读取部分:

# 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:

"""

水平条形图,需要修改以下属性

orientation="horizontal"

"""

import numpy as np

import matplotlib.pyplot as plt

# 数据

N = 5

x = [20, 10, 30, 25, 15]

y = [0,1,2,3,4]

# 绘图 x= 起始位置, bottom= 水平条的底部(左侧), 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()

注释2:plt.xticks的第一个参数和plt.plot的第一个参数一样,第二个参数是和第一个参数相同长度的list此例中用来代替横坐标

import matplotlib.pyplot as plt

x = [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 axes

plt.margins(0.2)

# Tweak spacing to prevent clipping of tick-labels

plt.subplots_adjust(bottom=0.15)

plt.show()

1.1 效果:

1.2 完整代码

import pandas as pd

import numpy as np

import xlrd

from matplotlib import pyplot

def drawBar(Music_genre,singer_num,year):

arr_len=len(Music_genre)

i=0

dict_music_singer={}

while i

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()

# 1930

workbook=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)

# 1940

workbook=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)

# 6

workbook=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)

# 9

workbook=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)

# 2000

workbook=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画图_python读取excel数据并且画图相关推荐

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

    一,要读取的数据的格式: 二,数据读取部分: b站视频参考:https://www.bilibili.com/video/BV14C4y1W7Nj?t=148 # 1930 workbook=xlrd ...

  2. 将excel转为python的字典_python读取excel表并把数据转存为字典

    excel表如下: 我们需要通过使用python的xlrd方法先读取excel,再遍历赋值给字典.代码如下: importxlrdclassRead_Ex():defread_excel(self): ...

  3. python 读取excel表格_Python读取Excel表格

    本文将教大家如何使用Python来读取Excel表,学会这个技能对提高工作效率会十分有帮助. 目录: 1.安装Python读excel模块--xlrd 2.准备表格内容 3.编写python代码并运行 ...

  4. python按行读取excel文件_python读取excel文件

    读取excel表格数据需要用到xlrd或者openpyxl模块,所以先安装xlrd/openpyxl:直接pip install xird/openpyxl xlrd和openpyxl区别: 1.xl ...

  5. python串口通信_python 读取串口数据的示例

    python3 读取串口数据 demo 最近在写一个demo,zigbee串口连接树莓派,树莓派使用串口通信接受zigbee穿过来得值.其中我是用的树莓派是3代B+,zigbee每隔三秒钟从串口输出数 ...

  6. python写入excel特定区域_Python读取Excel中符合特定条件的数据,并写入新的表格中...

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 原始表格 代码#!/usr/bin/env python # -*- coding: utf-8 ...

  7. 将excel转为python的字典_python读取excel数据转换成字典

    以上面的excel格式,输出字典类型: import xlrd def read_excel_data(): filename = 'E:\学历列表.xls' data = xlrd.open_wor ...

  8. python json操作_Python读取JSON数据操作实例解析

    读写 JSON 数据 问题 你想读写 JSON(JavaScript Object Notation) 编码格式的数据. 解决方案 json模块提供给了一种很简单的方式来编码和解码json数据,其中两 ...

  9. python读excel成数组_python读取excel数据 python怎么从excel中读取数据?

    python怎么从excel中读取数据?分母那么浩瀚,分子那么微弱.唯一就等于没有. #导入包 import xlrd #设置路径 path='C:\\Users\\jyjh\\Desktop\\da ...

最新文章

  1. 文巾解题 1046. 最后一块石头的重量
  2. 怎么提高es服务器的性能,es集群服务器配置规则是怎样的?什么是es集群
  3. python从date目录导入数据集_使用python划分数据集
  4. YUV常用的两种保存方式_YUY2和YV12
  5. 太赞了!阿里巴巴AI每天服务全球10亿人
  6. 关于“工作组管理员”
  7. ASP.NET MVC 3和Razor中的@helper
  8. wind7计算机控制面板在哪,联想win7系统控制面板在哪里打开
  9. [Android Pro] proguard.cfg 配置文件
  10. 社会学与计算机哪个考研容易,国内几所较热的社会学系考研难度比较
  11. 使用代理爬去微信公众号_微信公众号怎么去推广运营?企业微信公众号要如何运营?微信公众号运营技巧,你get了吗?微信怎么去推广运营?...
  12. 一张图了解大数据平台架构
  13. 解决“无法完成操作,因为文件包含病毒或潜在的垃圾软件”
  14. 肖秀荣教授:就考研政治来说
  15. 32位和64位操作系统及软件的区别
  16. 资源——对话框(Dialog Box)
  17. outlook插入html文件,Outlook正文插入附件?简单设置即可!
  18. android仿iphonex home,安卓高仿iPhoneX桌面
  19. Letasoft Sound Booster V1.1汉化破解版(系统音量增强软件)
  20. html yy直播,YY开播怎么捕捉窗口屏幕?设置直播范围介绍

热门文章

  1. 用友通账套备份操作流程
  2. 【Linux 性能优化系列】Linux 性能优化 -- CPU 性能篇(三) Linux 软中断
  3. addimitted_Chocolate Dessert Design Shop
  4. 通达OA开行业体验模式之先河
  5. 原生爬虫爬取虎牙绝地求生直播热度排行榜
  6. JAVA-生成二维码图片
  7. 首席新媒体运营教程:电商UGC社区运营全攻略电商
  8. 电脑升级到WIN11系统无法打开QQ和TIM?我来教你如何解决
  9. 江湖救急(处理域名未备案网站问题)
  10. spark入门案例以及sbt安装与打包(Linux环境)