猫史档案馆


【Python作品分享】图表生成器2.0【作品秀】

用户:穿山甲汤穿山甲汤查看:0 回复:0 评论:0 创建时间:2021-12-11T20:12:51


【作品展示】

center_image

 

【作品介绍】

1,新增河流图和说明书

2,优化脚本

 

【作品源代码】

from pyecharts import *
import webbrowser,turtle
import os
import json
print("記得保存")
print("欢迎使用图表生成器")
print("请选择模式")
z=int(input("柱状图摁1,折线图摁2,饼状图摁3,河流图摁4,说明书摁10"))
def chu():#分析数据
    s = turtle.Screen()
    y = int(s.textinput("选择打开方式", "(1是json,2是普通文档"))
    if y == 1:
        with open(s.textinput("输入", "输入json名称"), "r") as f:
            p = json.load(f)
    if y == 2:
        with open(s.textinput("输入", "输入文档名称"), "r", encoding="utf-8") as f:
            p = f.read()
    shu = list(p.keys())
    ju = list(p.values())
    print(shu, ju)
    return shu, ju
    
def zhu():#柱状图
    num = input("请输入名称")
    bar=Bar(num)
    shu,ju=chu()
    bar.add("",shu,ju)
    bar.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))
def zhe():#折线图
    num = input("请输入名称")
    l = Line(num)
    shu, ju = chu()
    l.add("", shu, ju)
    l.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))
def bing():#饼状图
    num = input("请输入名称")
    l = Pie(num)
    shu, ju = chu()
    l.add("", shu, ju)
    l.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))
def lei():#这里是河流图,分析数据方式不同
    s = turtle.Screen()
    y = int(s.textinput("选择打开方式", "(1是json,2是普通文档"))
    if y == 1:
        with open(s.textinput("输入", "输入json名称"), "r") as f:
            p = json.load(f)
    if y == 2:
        with open(s.textinput("输入", "输入文档名称"), "r", encoding="utf-8") as f:
                p = f.read()
    shu = p[input("键值对(x)")]
    ju = p[input("键值对(y)")]
    t = ThemeRiver("llll")
    t.add(shu, ju)
    t.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))

if z == 1:
    chu()
elif z==2:
    zhe()
elif z==3:
    bing()
elif z==4:
    lei()
else:
    print("1,必须是字典(套列表,(柱状图,折线图,饼状图))")
    print("2,文件和程序放一个文件夹(如桌面)")
    print("3,记得保存")


 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页