PySimpleGUI matplotlib 图形未显示为弹出 window,并且仅在笔记本中显示图形
PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook
我正在尝试 运行 此演示代码,并希望在我 运行 我的工具时显示图表的弹出窗口,并为用户提供横向单击进入下一个图表的选项。目前该图仅在我的 jupyter notebook 中的代码下绘制,而不是在我 运行 代码时作为弹出窗口绘制。我不确定为什么会这样?
我想要的示例:
matplotlib graph example
此处演示程序的代码:
from matplotlib import use
import PySimpleGUI as sg
import matplotlib.pyplot as plt
def draw_plot():
plt.plot([0.1, 0.2, 0.5, 0.7])
plt.show(block=False)
layout = [[sg.Button('Plot'), sg.Cancel(), sg.Button('Popup')]]
window = sg.Window('Have some Matplotlib....', layout)
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
elif event == 'Plot':
draw_plot()
elif event == 'Popup':
sg.popup('Yes, your application is still running')
window.close()
有人可以让我知道我在这里做错了什么吗?
谢谢
它可能是您当前正在使用的 IDE,但是当我执行您的代码时,会弹出一个单独的 window 和绘图。代码似乎已经完成了您希望它执行的操作。
我正在尝试 运行 此演示代码,并希望在我 运行 我的工具时显示图表的弹出窗口,并为用户提供横向单击进入下一个图表的选项。目前该图仅在我的 jupyter notebook 中的代码下绘制,而不是在我 运行 代码时作为弹出窗口绘制。我不确定为什么会这样?
我想要的示例:
matplotlib graph example
此处演示程序的代码:
from matplotlib import use
import PySimpleGUI as sg
import matplotlib.pyplot as plt
def draw_plot():
plt.plot([0.1, 0.2, 0.5, 0.7])
plt.show(block=False)
layout = [[sg.Button('Plot'), sg.Cancel(), sg.Button('Popup')]]
window = sg.Window('Have some Matplotlib....', layout)
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
elif event == 'Plot':
draw_plot()
elif event == 'Popup':
sg.popup('Yes, your application is still running')
window.close()
有人可以让我知道我在这里做错了什么吗? 谢谢
它可能是您当前正在使用的 IDE,但是当我执行您的代码时,会弹出一个单独的 window 和绘图。代码似乎已经完成了您希望它执行的操作。