在matplotlib中绘制图形时遇到的问题



我想做一个python项目,这是一个员工管理系统,我使用python的各种库,如tkinter, sqlite3(连接数据库),matplotlib。在建议的项目中,我们可以为员工添加、查看、更新、删除和绘制图表。我面临的问题是关于图表的。图的代码如下

from tkinter import *
from tkinter.messagebox import *
from tkinter.scrolledtext import *
from sqlite3 import *
import matplotlib.pyplot as plt
def graphback():
graph_window.deiconify()
main_window.withdraw
def graph():
con = None
try:
con = connect(project.db)
cursor = con.cursor()
sql = "select * from employee"
cursor.execute(sql)
data = cursor.fetchall()
name = []
salary = []
plt.plot(name, salary)
plt.title("Highest Salaried Employee")
plt.show
except Exception as e:
showerror("issue ", e)
con.rollback()
finally:
if con is not None:
con.close()

def mgraph():
main_window.deiconify()
graph_window.withdraw()

当我运行代码时,我无法得到图形。我应该做些什么来运行代码?

您错过了plt.show周围的括号,否则您不会调用该函数。

改为

from tkinter import *
from tkinter.messagebox import *
from tkinter.scrolledtext import *
from sqlite3 import *
import matplotlib.pyplot as plt
def graphback():
graph_window.deiconify()
main_window.withdraw
def graph():
con = None
try:
con = connect(project.db)
cursor = con.cursor()
sql = "select * from employee"
cursor.execute(sql)
data = cursor.fetchall()
name = []
salary = []
plt.plot(name, salary)
plt.title("Highest Salaried Employee")
# SEE HERE
plt.show()
except Exception as e:
showerror("issue ", e)
con.rollback()
finally:
if con is not None:
con.close()

def mgraph():
main_window.deiconify()
graph_window.withdraw()

相关内容

  • 没有找到相关文章

最新更新