<code>import matplotlib.pyplot as plt def onclick(event): # This prints both times print(event.xdata, event.ydata) # This only works the first time plt.scatter(event.xdata, event.ydata) for i in range(2): plt.plot([1, 2, 3, 4]) plt.gca().figure.canvas.mpl_connect('button_press_event', onclick) with plt.ion(): plt.show(block=True) </code>

问题描述 投票:0回答:0

plt.close()
作为内部循环的最后一步

plt.pause(1)

作为内部循环的最后一步

使用

plt.ion()
  • plt.ioff()
  • 而不是上下文管理器
  • 使用CID返回
    canvas.mpl_disconnect(cid)
  • mpl_connect
  • plt.draw()
    尝试强制更新
    复印和粘贴相同的代码两次,而不是使用循环
  • 在循环中使用
  • plt.pause(1)
    ,然后在
    fig, ax = plt.subplots()
    处理程序中明确绘制到同一轴
  • 我使用Matplotlib 3.9.4在Python 3.9.20中与我无法控制的事物兼容。
  • 在通过控制台上进行一些减弱,我能够使其正常工作。在循环末尾添加相同的命令使点显示在第二个窗口中。
    
    ax.scatter()
python matplotlib plot interactive ipympl
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.