matplotlib按钮未显示在同一窗口上



我用matplotlib制作了一个简单的GUI游戏,如果我在配置选项中选中"Run with Python Console",我可以让它在PyCharm上运行良好。

当我试图通过从终端运行它时,问题就来了

python MyGame.py

事实上,在执行此操作时,matplotlib窗口只显示绘图,而不显示小部件按钮,并且当我关闭第一个窗口时,后者只显示在第二个窗口中。。。

有没有一种方法可以在同一个窗口中获得所有的绘图和按钮,就像在PyCharm中使用我的配置一样?

以下是具有意外行为的代码示例

import matplotlib.pyplot as plt
import matplotlib.widgets as widgets
ax = plt.subplot()
ax.plot(.5,.6, marker='o', markersize=15, color='k')
plt.show()
buttonShape = plt.axes([.4, .2, .2, .1])
button = widgets.Button(buttonShape, "I am a button")
plt.show()

谢谢,

Vic

您的代码中有两个plt.show((。第一个显示了您迄今为止构建的图形。然后用鼠标将其关闭。然后你开始建造一个新的。只需移除第一个plt.show((

最新更新