簡體   English   中英

使用 sqlite3 在 python 中缺少圖形數據

[英]Missing graph data in python using sqlite3

我正在開發一個學生管理系統,該系統基本上執行 CURD 操作並顯示學生與分數的條形圖。 我已經搜索了如何使用數據庫中的數據繪制 plot 圖形,並嘗試使用我的參數來編寫代碼。 但我似乎無法將數據放入圖表中,但軸是制作的。 我能得到一些關於我應該如何改變我的代碼的指示嗎?

這是我寫的代碼:

        charts_window.deiconify()
        main.withdraw()
        con = None
        try:
            con = connect('omkar.db')
            cursor = con.cursor()
            def graph():
                cursor.execute("SELECT name , marks FROM student")
                data = cursor.fetchall()
                students = []
                scores = []
                for d in data:
                    students.append(d[0])
                    scores.append(d[1])

                plt.bar('students','scores',color = ['red','green'])
                plt.xlabel("students")
                plt.ylabel("scores")
                plt.title('Results')
            
                plt.show()
                con.commit()
            graph()
        except Exception as e:
            showerror('ERROR',e)
            
        finally:
            if con is not None:
                con.close()

以下是圖表屏幕的顯示方式:

圖表

在行

plt.bar('students','scores',color = ['red','green'])

學生和分數參數應該是字符串嗎? 嘗試:

plt.bar(students, scores, color = ['red', 'green'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM