怎么用python画条形图
发表于:2025-11-08 作者:千家信息网编辑
千家信息网最后更新 2025年11月08日,这篇文章主要介绍"怎么用python画条形图",在日常操作中,相信很多人在怎么用python画条形图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎么用python画条
千家信息网最后更新 2025年11月08日怎么用python画条形图
这篇文章主要介绍"怎么用python画条形图",在日常操作中,相信很多人在怎么用python画条形图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎么用python画条形图"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
在做毕设的过程中有些数据用表格来展现,会很难看出数据之间的差别,凸显不出数据的特点,所以想制作一个条形图,这里特地记录下,已备以后用到。
import numpy as npimport matplotlib.pyplot as pltimport matplotlib#指定默认字体matplotlib.rcParams['font.sans-serif'] = ['FangSong']matplotlib.rcParams['font.family']='sans-serif' c101= (8,7,3,7,10,4,11,8,11,10,8,9)c102= (21,21,24,25,16,17,11,24,24,25,36,33)c103= (4,4,10,3,9,8,12,2,4,5,2,6)c104= (1,5,1,3,2,3,3,3,6,5,1,0)c105= (3,1,0,1,3,3,1,2,0,0,0,0)c106= (1,2,0,0,1,1,0,0,1,1,0,0)c107= (1,0,1,0,0,1,0,0,0,0,0,0)c108= (0,1,0,0,0,2,1,1,0,1,0,0)c109= (1,0,1,1,0,0,1,1,0,0,0,0) ind = np.arange(0,24,2) # the x locations for the groupswidth = 0.2 # the width of the bars fig,ax = plt.subplots()rects1 = ax.bar(ind + width, c101, width, color='SkyBlue',align='edge', label='101')rects2 = ax.bar(ind + 2*width, c102, width,color='IndianRed',align='edge', label='102')rects3 = ax.bar(ind + 3*width, c103, width, color='Cyan',align='edge', label='103')rects4 = ax.bar(ind + 4*width, c104, width, color='Magenta',align='edge', label='104')rects5 = ax.bar(ind + 5*width, c105, width, color='Purple',align='edge', label='105')rects6 = ax.bar(ind + 6*width, c106, width, color='Green',align='edge', label='106')rects7 = ax.bar(ind + 7*width, c107, width, color='Yellow',align='edge', label='107')rects8 = ax.bar(ind + 8*width, c108, width, color='Blue',align='edge', label='108')rects9 = ax.bar(ind + 9*width, c109, width, color='Orange',align='edge', label='109') # Add some text for labels, title and custom x-axis tick labels, etc.#ax.set_title('Scores by group and gender')plt.xticks(ind,('1班', '2班', '3班', '4班', '5班','6班','7班','8班','9班','10班','11班','12班'))ax.legend(loc='upper center') plt.show()fig.savefig('./test77.jpg')
竖起来的
%matplotlib notebookimport matplotlib.pyplot as pltimport pandas as pdimport numpy as npimport seaborn as snsimport matplotlib#指定默认字体matplotlib.rcParams['font.sans-serif'] = ['FangSong']matplotlib.rcParams['font.family']='sans-serif'#解决负号'-'显示为方块的问题matplotlib.rcParams['axes.unicode_minus'] = Falsedata = [[8, 21, 4, 1, 3, 1, 1, 0, 1], [7,21,4,5,1,2,0,1,0], [3,24,10,1,0,0,1,0,1], [7,25,3,3,1,0,0,0,1], [10,16,9,2,3,1,0,0,0], [4,17,8,3,3,1,1,2,0], [11,11,12,3,1,0,0,1,1], [8,24,2,3,2,0,0,1,1], [11,24,4,6,0,1,0,0,0], [10,25,5,5,0,1,0,1,0], [8,36,2,1,0,0,0,0], [9,33,6,0,0,0,0,0]]df = pd.DataFrame(data, index=['1班','2班','3班','4班','5班','6班','7班','8班','9班','10班','11班','12班'], columns=pd.Index(['101','102','103','104','105','106','107','108','109']), )df.plot(kind='barh',figsize=(5,8)) plt.show()#fig.savefig('./test2.jpg')到此,关于"怎么用python画条形图"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
条形
学习
数据
字体
更多
问题
帮助
实用
难看
接下来
之间
差别
文章
方块
方法
特点
理论
知识
篇文章
网站
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
一个软件需要多少带宽的服务器
安图恩一直连接服务器
路由,交换及安全等网络技术
商飞网络安全
新新网络安全插画
万兴网络技术有限公司
网站数据库安全技术研究论文选题
把服务器放在多少温度下
渭南艺红网络技术有限公司
主题班会网络安全发言
民意网络安全
金属材料性能数据库免费
怎么创建数据库sql代码
食物语服务器在哪
网络安全和运维哪个难
数据库学生表删除列
王春晖教授网络安全
mac 查看数据库工具
怎么做企业内网网络安全
大方软件开发app
关于中学生网络安全的剧本
时间戳服务器集成
服务器炒股
数据库保存树结构
安全通防攻击服务器
互联网医院网络安全解决方案
山西公安服务器繁忙是什么意思
水稻蛋白数据库
计算机软件开发是干嘛的
汽车技术 车载网络技术