猫史档案馆


【Python作品分享】星座饼状图统计

用户:UMSUMS查看:0 回复:1 评论:0 创建时间:2020-05-17T13:51:37


【作品展示】

center_image

 

【作品介绍】

数据要自己输入,pyecharts是第三方库,也要自己导入

 

【作品源代码】

from pyecharts import Pie
import webbrowser
import os
import json

with open(r"C:\编程\birthdaylist.json","r")as f:#导入数据,自己做数据,txt和json都行
    data=json.load(f)

constellation={#输入星座,不要改动
    "水瓶座":0,
    "双鱼座":0,
    "白羊座":0,
    "金牛座":0,
    "双子座":0,
    "巨蟹座":0,
    "狮子座":0,
    "喵座":0,
    "天秤座":0,
    "天蝎座":0,
    "射手座":0,
    "魔蝎座":0,
}

for birthday in data:#分类数据,不要改动
    if 1.20 <= birthday <= 2.18:
        constellation["水瓶座"] += 1
    elif 2.19 <= birthday <= 3.20:
        constellation["双鱼座"] += 1
    elif 3.21 <= birthday <= 4.19:
        constellation["白羊座"] += 1
    elif 4.20 <= birthday <= 5.20:
        constellation["金牛座"] += 1
    elif 5.21 <= birthday <= 6.21:
        constellation["双子座"] += 1
    elif 6.22 <= birthday <= 7.22:
        constellation["巨蟹座"] += 1
    elif 7.23 <= birthday <= 8.22:
        constellation["狮子座"] += 1
    elif 8.23 <= birthday <= 9.22:
        constellation["喵座"] += 1
    elif 9.23 <= birthday <= 10.23:
        constellation["天秤座"] += 1
    elif 10.24 <= birthday <= 11.22:
        constellation["天蝎座"] += 1
    elif 11.23 <= birthday <= 12.21:
        constellation["射手座"] += 1
    else:
        constellation["魔蝎座"] += 1

key=list(constellation.keys())
value=list(constellation.values())
pie=Pie("星座统计",title_pos="center")
pie.add(
    "",
    key,
    value,
    legend_pos="left",
    legend_orient="vertical",
    is_label_show=True
)
pie.render()

webbrowser.open("file://"+os.path.realpath("render.html"))

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
禁止挖坟后果自负禁止挖坟后果自负

from pyecharts import Pie import webbrowser import os import json with open("birthdaylist.json","r")as f: d=json.load(f) constellation = { "水瓶座":0, "双鱼座":0, "白羊座":0, "金牛座":0, "双子座":0, "巨蟹座":0, "狮子座":0, "喵座":0, "天秤座":0, "天蝎座":0, "天蝎座":0, "摩羯座":0, } for b in d: if1.20<=b<=2.18: constellation["水瓶座"] += 1 elif2.19<= b <=3.20: constellation["双鱼座"] += 1 elif3.21<= b <=4.19: constellation["白羊座"] += 1 elif4.20<= b <= 5.20: constellation["金牛座"] += 1 elif5.21<= b <= 6.21: constellation["双子座"] += 1 elif6.22<= b <= 7.22: constellation["巨蟹座"] += 1 elif7.23<= b <= 8.22: constellation["狮子座"] += 1 elif8.23<= b <= 9.22: constellation["喵座"] += 1 elif9.23<= b <= 10.23: constellation["天秤座"] += 1 elif10.24<= b <= 11.22: constellation["天蝎座"] += 1 elif11.23<= b <= 12.21: constellation["天蝎座"] += 1 else: constellation["摩羯座"] += 1 print(constellation) key = list(constellation.keys()) value=list(constellation.values()) pie=Pie("班级星座统计") pie.add( "", key, value, legend_pos="left", legend_orient="vertical", is_label_show=True,
) pie.render() webbrowser.open("file://"+os.path.realpath("render.html"))

点赞0


评论