猫史档案馆


【Python作品分享】G6 25课【作业帖】

用户:Mr_AccordingMr_According查看:0 回复:1 评论:0 创建时间:2019-08-19T15:06:10


【作品展示】

center_image

 

【作品介绍】

班级星座统计

 

【作品源代码】

from pyecharts import Pie
import webbrowser
import os
import json

with open("birthdaylist.json","r") as f:
    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"
)
pie.render()
webbrowser.open("file://" + os.path.realpath("render.html"))

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
QBZ_QBZ_

把一个pyecharts饼图(甚至没有做改动的代码)放出来刷帖真的好吗?

点赞0


评论