weixin_57733352 2021-06-06 09:52 采纳率: 100%
浏览 31
已采纳

在python中如何将一个文本数据导入图表中

答案一定能在python2.7上实现,这是我的数据

这是我的图表

from Tkinter import *

def getMarks():
    a,b,c,d,f = 0,0,0,0,0
    mark = input("Enter a mark (-1 to finish): ")
    while mark >= 0:
        if mark >= 90:
            a = a + 1
        elif mark >= 80:
            b = b + 1
        elif mark >= 70:
            c = c + 1
        elif mark >= 60:
            d = d + 1
        else:
            f = f + 1
        mark = input("Enter a mark (-1 to finish): ")
    return a,b,c,d,f

def getDefaultMarks():
    return 5,8,10,12,13        
    
def create_grade_piechart(a,b,c,d,f):
    #a,b,c,d,f = getMarks()
    #a,b,c,d,f = getDefaultMarks()
       
    win = Tk()
    cv = Canvas(win,width=300,height=200,bg="white")
    cv.pack()

    n = a+b+c+d+f
    eA,sA = 360.0*a/n,0
    eB,sB = 360.0*b/n,eA
    eC,sC = 360.0*c/n,eA+eB
    eD,sD = 360.0*d/n,eA+eB+eC
    eF,sF = 360.0*f/n,eA+eB+eC+eD
     
    bb = (90,40,210,160)
    pieA = cv.create_arc(bb,start=sA,extent=eA,fill="yellow")
    pieB = cv.create_arc(bb,start=sB,extent=eB,fill="green")
    pieC = cv.create_arc(bb,start=sC,extent=eC,fill="black")
    pieD = cv.create_arc(bb,start=sD,extent=eD,fill="gray")
    pieF = cv.create_arc(bb,start=sF,extent=eF,fill="red")

    cv.create_rectangle(240,40,260,50,fill="yellow")
    cv.create_rectangle(240,40+24,260,50+24,fill="green")    
    cv.create_rectangle(240,40+48,260,50+48,fill="black")
    cv.create_rectangle(240,40+72,260,50+72,fill="gray")
    cv.create_rectangle(240,40+96,260,50+96,fill="red")

    cv.create_text(270,40,text="A",anchor=N)
    cv.create_text(270,40+24,text="B",anchor=N)    
    cv.create_text(270,40+48,text="C",anchor=N)
    cv.create_text(270,40+72,text="D",anchor=N)    
    cv.create_text(270,40+96,text="F",anchor=N)

    piepct = cv.create_text(40,100,text="")
    
    def inPieA(event):
        pct = "%5.1f%%" % (100.0*a/n)
        cv.itemconfig(piepct,text=pct)

    def inPieB(event):
        pct = "%5.1f%%" % (100.0*b/n)
        cv.itemconfig(piepct,text=pct)

    def inPieC(event):
        pct = "%5.1f%%" % (100.0*c/n)
        cv.itemconfig(piepct,text=pct)

    def inPieD(event):
        pct = "%5.1f%%" % (100.0*d/n)
        cv.itemconfig(piepct,text=pct)

    def inPieF(event):
        pct = "%5.1f%%" % (100.0*f/n)
        cv.itemconfig(piepct,text=pct)

    cv.tag_bind(pieA,"<Enter>",inPieA)
    cv.tag_bind(pieB,"<Enter>",inPieB)
    cv.tag_bind(pieC,"<Enter>",inPieC)
    cv.tag_bind(pieD,"<Enter>",inPieD)
    cv.tag_bind(pieF,"<Enter>",inPieF)
  
    win.mainloop()

def main():
    #a,b,c,d,f = getDefaultMarks()
    #create_grade_piechart(a,b,c,d,f)
    create_grade_piechart(11,4,3,5,5)

if __name__ == '__main__':
    main()
    pass

如何让文本数据中score旁边那一列的数字,导入做好的图表中,原本的图表是交互式的你要自己输入数据,我现在数据列好了,如何输给图表,并通过图表展示。希望能写一下代码,谢谢

  • 写回答

2条回答 默认 最新

  • CSDN专家-Time 2021-06-06 09:53
    关注

    python有charts直接给数据list就好了

    https://www.cnblogs.com/jyroy/p/9446486.html 这里有详细教程

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line