栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使交互式matplotlib窗口在每次更新时都不会弹出到前面(Windows 7)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使交互式matplotlib窗口在每次更新时都不会弹出到前面(Windows 7)

改变后端

该问题似乎仅在

Tk
后端存在。使用
Qt
后端,窗口将保持在使用进行更新时的位置
plt.pause

要更改后端,请在脚本开头使用这些行。

import matplotlibmatplotlib.use("Qt4agg") # or "Qt5agg" depending on you version of Qt

修改中
plt.pause

如果不能更改后端,则可能有帮助。窗口不断弹出的原因是内部

plt.pause
调用
plt.show()
。因此,您
pause
无需调用即可实现自己的功能
show
。这要求首先处于交互模式
plt.ion()
,然后至少调用一次
plt.show()
。之后,您可以使用自定义
mypause
功能更新图,如下所示。

import matplotlibmatplotlib.use("TkAgg")import matplotlib.pyplot as pltfrom time import timefrom random import randomplt.ion()# set up the figurefig = plt.figure()plt.xlabel('Time')plt.ylabel('Value')plt.show(block=False)def mypause(interval):    backend = plt.rcParams['backend']    if backend in matplotlib.rcsetup.interactive_bk:        figManager = matplotlib._pylab_helpers.Gcf.get_active()        if figManager is not None: canvas = figManager.canvas if canvas.figure.stale:     canvas.draw() canvas.start_event_loop(interval) returnt0 = time()t = []y = []while True:    t.append( time()-t0 )    y.append( random() )    plt.gca().clear()    plt.plot( t , y )    mypause(1)

使用
animation

最后,使用

matplotlib.animation
类将使以上所有内容都过时。matplotlib页面上
matplotlib.animation.FuncAnimation
显示了一个示例。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/652890.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号