猫史档案馆


【Python作品分享】统计图输出机6.0【作品秀】

用户:RainerNeverGotRainerNeverGot查看:0 回复:0 评论:0 创建时间:2020-12-13T17:17:31


【作品展示】

center_image

 

【作品介绍】

将大量重复代码整合,改成循环结构,增加了可读性,减少大量占用空间

 

【作品源代码】

#导入库
from pyecharts import Bar,Pie,Funnel,Liquid,Radar,HeatMap
import webbrowser
import os

o=0
p=0
q=0
r=0
s=0
t=0
u=0
v=0
w=0
x=0
y=0
z=0

name=[o,p,q,r,s,t]
num=[u,v,w,x,y,z]

x12=["请输入第一个数据:","请输入第二个数据:","请输入第三个数据:","请输入第四个数据:","请输入第五个数据:","请输入第六个数据:"]
y12=["请输入第一个数据的名称:","请输入第二个数据的名称:","请输入第三个数据的名称:","请输入第四个数据的名称:","请输入第五个数据的名称:","请输入第六个数据的名称:"]

a=[]
b=[]

#统计图输出模块
def end1():
    print(" ")
    print("统计图名称")
    l = input("请输入统计图的名称:")

    c = Bar(l, title_pos="center")
    c.add("", a, b, is_label_show=True, mark_line=["average"], mark_point=["max", "min"], is_more_utils=True) 
    c.render()

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


def end2():
    print(" ")
    print("统计图名称")
    l = input("请输入统计图的名称:")

    c = Bar(l, title_pos="center")
    c.add("", a, b, is_label_show=True, mark_line=["average"],is_more_utils=True)
    c.render()

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


def end3():
    print(" ")
    print("统计图名称")
    l = input("请输入统计图的名称:")

    c = Bar(l, title_pos="center")
    c.add("", a, b, is_label_show=True,mark_point=["max", "min"],is_more_utils=True)
    c.render()

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


def end4():
    print(" ")
    print("统计图名称")
    l = input("请输入统计图的名称:")

    c = Bar(l, title_pos="center")
    c.add("", a, b, is_label_show=True, is_more_utils=True)
    c.render()

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

def fun1():
    opq.add(n, b, a, a_sort="ascending", is_label_show=True)
    opq.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))

def fun2():
    opq.add(n, b, a, a_sort="decending", is_label_show=True)
    opq.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))

#程序模块
print("统计图生成程序6.0","\n")

pieo=int(input("请选择统计图为条形或扇形(条形(可转为折线)选1,扇形选2,漏斗选3,水球图选4,雷达图选5):"))

if pieo==1:
    print(" ")
    print("条形或折线统计图")    
    #判断数量
    com=int(input("请输入要呈现的数据个数(最大为6,最小为2):"))
    if com>=2 and com<=6:
        print(" ")
        print("请输入高度数据")
        for i in range(com):
            num[i]=float(input(x12[i]))
            a.append(num[i])
        print(" ")
        print("请输入名称")
        for j in range(com):
            name[j]=input(y12[j])
            b.append(name[j])
        print(" ")
        ooo = int(input("是否显示平均值(是敲1,否敲2)?"))
        ppp = int(input("是否显示最大与最小值(是敲1,否敲2)?"))
        if ooo == 1 and ppp == 1:
            end1()
        elif ooo == 1 and ppp == 2:
            end2()
        elif ooo == 2 and ppp == 1:
            end3()
        elif ooo == 2 and ppp == 2:
            end4()

    #异常数量结尾
    else:
        print(" ")
        print("您的输入有误,程序结束。")

elif pieo==2:
    print(" ")
    print("扇形统计图")
    lpl=int(input("请选择扇形的个数(最大为6,最小为2):"))
    if lpl>=2 and lpl<=6:
        print(" ")
        print("请输入数据")
        for i in range(lpl):
            num[i]=float(input(x12[i]))
            a.append(num[i])
        print(" ")
        print("请输入名称")
        for j in range(lpl):
            name[j]=input(y12[j])
            b.append(name[j])
        print(" ")
        zzz=input("请输入统计图名称:")
        pi = Pie(zzz)
        pi.add("", b, a, legend_pos="right",
            legend_orient="vertical", is_label_show=True)
        pi.render()
        webbrowser.open("file://"+os.path.realpath("render.html"))

    else:
        print("您的输入有误,程序结束。")

elif pieo==3:
    iii=int(input("请输入层数(最大为6,最小为2):"))
    if iii>= 2 and iii<=6:    
        print(" ")
        abc=input("请输入名称:")
        opq=Funnel(abc)
        print(" ")
        print("数据输入")
        for i in range(iii):
            num[i]=float(input(x12[i]))
            a.append(num[i])
        print(" ")
        print("名称输入")
        for j in range(iii):
            name[j]=input(y12[j])
            b.append(name[i])    
        print("程序加载中,请稍后。")
        n=""
        ejw=int(input("统计图样式(漏斗图敲1,金字塔图敲2):"))
        if ejw==1:
            fun2()
        elif ejw==2:
            fun1()
        
    else:
        print("您的输入有误,程序结束。")

elif pieo==4:
    m=input("请输入标题:")
    n=input("请输入占比(数值为小于1的小数)")
    l = Liquid(m)
    l.add("Liquid", [n])
    l.render()
    webbrowser.open("file://"+os.path.realpath("render.html"))


elif pieo==5:
    we=int(input("请输入标签个数(最小为3,最大为6):"))
    you=float(input("请输入标签最大值:"))
    if we>=3 and we<=6:
        print(" ")
        for i1 in range(we):
            name[i1]=input(y12[i1])
        for i2 in range(we):
            a.append({"name":name[i2],"max":you})
        print(" ")
        for j in range(we):
            num[j]=float(input(x12[j]))
            b.append(num[j])
        print(" ")
        skl=input("请输入标题:")
        title = Radar(skl)
        title.config(c_schema=a)
        title.add(skl, [b])
        title.render()
        webbrowser.open("file://"+os.path.realpath("render.html"))

    else:
        print("您的输入有误,程序结束。")

else:
    print("您的输入有误,程序结束。")

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页