用户:
Kimi_hjh查看:0 回复:0 评论:0 创建时间:2022-06-18T15:48:12
【作品展示】

【作品介绍】
饼状图
【作品源代码】
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",
is_label_show=True
)
pie.render()
webbrowser.open("file://" + os.path.realpath("render.html"))
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn