我有一个Tkinter GUI,它创建预算计算器并存储事务。GUI上的一个按钮是调用脚本,该脚本从事务数据创建图表
我第一次单击按钮时,图形打开得很好。如果我再次尝试单击按钮,会出现一个空白数字。我相信这是我最初的
plt.show()
在我画图表的地方打电话。以前有人遇到过这样的问题吗
GUI代码:
ViewCharts = Button(win,text = 'View Spending Charts')
ViewCharts.grid(row = 21,column = 1)
def view_charts():
Graphs.plot_charts()
ViewCharts.configure(command = view_charts)
图表代码:
global fig
fig = plt.figure(figsize=(12, 9))
fig.subplots_adjust(hspace=.5)
global ax1
ax1 = fig.add_subplot(1,2,1)
global ax2
ax2 = fig.add_subplot(1,2,2)
def plot_charts():
category_bar_chart()
category_pie_chart()
fig = plt.show()
其中,category_bar_chart()和category_pie_chart()只是将绘图添加到ax1和ax2中的函数
非常感谢您的任何帮助或建议!我正在Mac/PC上使用Python3,具体取决于一天中的时间。谢谢
问题是,当您重新定义
fig
时,您正在重新定义fig = plt.show()
,因此在第一次调用之后,绘图不再存储在任何位置。只需执行plt.show()
即可相关问题 更多 >
编程相关推荐