本文使用python中的itchat模块获取微信信息,并用matlab进行数据显示,这两个模块没有的可直接在控制台 pip install ** 进行安装,话不多说,先上效果图

一、男女比例分析

二、各个地区的男女数量-柱状图

三、各个地区的男女数量-横向柱状图(地区标签比较清晰)

下来一 一上代码,做这个主要还是看数据怎么分析,以及运用下图表的显示方式,matlab挺强大的,支持一下

一,饼状图代码

import itchat, time
import matplotlib.pyplot as plotdef chatProportion():itchat.auto_login(True)male = female = other = 0rName = "群名称,自己填"roomSum = 0chatRooms = itchat.search_chatrooms(name=rName)if chatRooms is None:print("no this:" + rName)else:chatRoom = itchat.update_chatroom(chatRooms[0]['UserName'], detailedMember=True)index = 0mem_list = chatRoom['MemberList']roomSum = len(mem_list)for friend in mem_list:dis = friend['DisplayName']nick = friend['NickName']sex = friend['Sex']if sex == 1:male += 1elif sex == 2:female += 1else:other += 1index += 1print(index,dis,nick,sex)labels = ['男:'+str(male),'女'+str(female),'其他'+str(other)]sizes = [male, female, other]colors = ['green','red','gray']# 几个分量向外偏移explode = (0.1,0.1,0)plot.pie(sizes,explode,labels,colors,'%2.0f%%')plot.axis('equal')plot.legend(loc='upper left', bbox_to_anchor=(-0.1, 1))plot.rcParams['font.sans-serif'] = ['Microsoft YaHei']plot.rcParams['axes.unicode_minus'] = Falseplot.title("群名:"+str(rName)+"[总人数:"+str(roomSum)+"]\n"+str("(男女比例分析-流年master出品)"))plot.grid()plot.show()if __name__ == "__main__":chatProportion()

二、柱状图代码

import itchat, time
import matplotlib.pyplot as pltdef getInfo():# 测试数据# info = []# city_list = ["西安","大理","西安","city","西安","西安","","大理"]# sex_list = ["男","女","男"]# for city in city_list:#     for sex in sex_list:#         per_info = {#             'city':None,#             'sex':None#         }#         if city == "":#             city = "其他"#         per_info['city'] = city#         per_info['sex'] = sex#         info.append(per_info)# return infodata_info = []itchat.auto_login(True)rName = "群名称,自己填"chatRooms = itchat.search_chatrooms(name=rName)if chatRooms is None:print("no this:" + rName)else:chatRoom = itchat.update_chatroom(chatRooms[0]['UserName'], detailedMember=True)mem_list = chatRoom['MemberList']for friend in mem_list:sex = friend['Sex']city = friend['City']per_info = {'city':None,'sex':None}if city == "":city = "其他"per_info['city'] = cityper_info['sex'] = sexdata_info.append(per_info)return data_infodef cityData():info = getInfo()city_list = []for ereryOne in info:city_list.append(ereryOne['city'])# 归一去重single_list = set(city_list)men_arr = []women_arr = []for single in single_list:men_count = 0women_count = 0for everyOne in info:if everyOne['city'] == single:if everyOne['sex'] == 1 or everyOne['sex'] == "男":men_count += 1else:women_count += 1men_arr.append(men_count)women_arr.append(women_count)wid = 0.4ax = plt.subplot()x_dir = list(range(len(single_list)))# 第二个柱状图偏移一点x_dir2 = [x_dir[i] + wid for i in range(len(x_dir))]tick_loc = [ i + wid/2 for i in range(len(single_list))]# 1 竖向柱状图# label1 = plt.bar(x_dir, men_arr, width=wid, fc='gray')# for rect in label1:#     height = rect.get_height()#     # .-0.1 : 反向移动0.1#     plt.text(rect.get_x()+rect.get_width()/2.-0.1, 1.03*height, "%s" % float(height))# label2 = plt.bar(x_dir2, women_arr, width=wid, fc='r')# for rect in label2:#     height = rect.get_height()#     plt.text(rect.get_x()+rect.get_width()/2.-0.1, 1.03*height, "%s" % float(height))# # 横向标签位置# ax.set_xticks(tick_loc)# # 横向标签名称# ax.set_xticklabels(single_list)# plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']# plt.title("男女地区竖向柱状图")# plt.show()# 2 横向柱状图label1 = ax.barh(x_dir, men_arr, height=wid, fc='gray')for rect in label1:w = rect.get_width()ax.text(w, rect.get_y()+rect.get_height()/2, '%d'%int(w), ha='left',va='center')label2 = ax.barh(x_dir2, women_arr, height=wid, fc='r')for rect in label2:w = rect.get_width()ax.text(w, rect.get_y()+rect.get_height()/2, '%d'%int(w), ha='left',va='center')# 纵向标签位置ax.set_yticks(tick_loc)# 纵向标签名称ax.set_yticklabels(single_list)plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']plt.title("男女地区横向柱状图")plt.show()if __name__ == "__main__":cityData()

python 微信群男女比例分析,区域分析,柱状图显示相关推荐

  1. 基于Python的微信好友男女比例,区域排名,签名情感分析

    项目源码下载地址:https://download.csdn.net/download/sheziqiong/85609539 wechat 微信好友男女比例,区域排名,签名情感分析 程序 备注 技术 ...

  2. 基于微信好友用户的男女比例,区域排名,签名情感分析

    wechat 微信好友男女比例,区域排名,签名情感分析 程序 备注 技术栈 微信好友性别占比 采集微信好友性别比例并绘制饼图 itchat, matplotlib 微信好友头像 采集微信好友头像并拼接 ...

  3. chatgpt赋能python:Python微信聊天记录:如何导出并分析聊天记录

    Python 微信聊天记录:如何导出并分析聊天记录 微信是目前最受欢迎的聊天工具之一,但是它的聊天记录并不方便导出和分析.本文将介绍如何使用 Python 导出微信聊天记录,并进行分析. 导出微信聊天 ...

  4. Python查看微信好友男女比例及地域为位置和图灵机器人自动聊天

    首先在pycharm中 安装:wxpy 支持 Python 3.4-3.6,以及 2.7 版本 pip install -U wxpy 安装 pillow模块 pip install pillow 安 ...

  5. python微信群管理_利用python实现在微信群刷屏的方法

    hello,我是小小炽,这是我写的第一篇博客,写博客一直都想在写,但是苦于能力尚浅,在各位大牛面前那既然是关公面前耍大刀了,但是其实想来每一个大牛不也是从一个小白慢慢进步学习从而达到一定的高度的吗,而 ...

  6. python微信群管理_python获取微信群和群成员

    首先用命令pip install itchat安装itchat,然后进到你要获取的群里去选择"保存到通讯录"那里将选项滑到右边选上,没有保存到通讯录的群是取不到信息的. 以下代码在 ...

  7. python字典统计男女比例_Python 自动统计微博抽奖中奖男女比例(附代码)

    今天来写一个自动计算微博抽奖男女比例的代码,很早就应该发这篇了,只是不想蹭热点(才不是拖更). 整个的过程大概分为三步: S1:从抽奖公示页获取所有中奖者的微博ID S2:由每个中奖者的微博ID进入其 ...

  8. python字典统计男女比例_python统计男女比例-女性时尚流行美容健康娱乐mv-ida网...

    女性时尚流行美容健康娱乐mv-ida网 mvida时尚娱乐网 首页 美容 护肤 化妆技巧 发型 服饰 健康 情感 美体 美食 娱乐 明星八卦 首页  > 高级搜索 python 实现代码行数 统 ...

  9. python微信群机器人统计群数据_python-itchat 统计微信群、好友数量的实例

    Python Python开发 Python语言 python-itchat 统计微信群.好友数量的实例 今天小编就为大家分享一篇python-itchat 统计微信群.好友数量,及原始消息数据的实例 ...

最新文章

  1. QQ交流群,欢迎有兴趣的同学加入。
  2. Comet OJ - Contest #2题解
  3. 数据结构 稀疏矩阵的实现方法
  4. IE 中释放javascript对象
  5. 使用MQTT.fx接入阿里云物联网平台
  6. Mac OS使用技巧之十三:Finder中标记的使用
  7. C++----练习--string输入输出
  8. java条件运算查询学生成绩_java条件运算符的应用实例之成绩分级
  9. flutter弹框怎么封装_Flutter初始化时 弹出弹出框
  10. 计算机词汇 音标,计算机词汇带音标word版本.pdf
  11. 使用java实现软件结构体系中的管道-过滤器模式
  12. 看美文,记单词(5)
  13. Kanade Loves Maze Designing
  14. 雷军和董明珠的10亿赌局 什么来历
  15. Python安装教程_Python运行环境的搭建
  16. PostgreSQL集群篇——PostgreSQL的配置文件解析
  17. python视频教程哪个好-Python 基础视频教程那个好?
  18. linux中有一个备份程序,技术|SBackup: 一个Linux下的简单备份软件
  19. win10计算机里的工具在哪里设置,win10系统桌面上添加自带日历小工具的设置办法...
  20. TensorFlow 特征列介绍

热门文章

  1. 三网融合专家吴纯勇:电脑处理器融合势成必然
  2. [python]编写程序产生 ISBN 号的校验位。
  3. 分享一个properties转YAML小工具
  4. decode和encode
  5. Java Web应用开发——作业四
  6. CS5266设计TYPEC转HDMI带PD和USB3.1数据传输USB-C扩展坞方案
  7. java计算机毕业设计家居门户网站MyBatis+系统+LW文档+源码+调试部署
  8. 简单工厂之Delphi实现
  9. 寄居蟹与海葵c语言大作业,寄居蟹如何与海葵共生
  10. idea 撤销本地commit 但是未push的代码