您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python 2,matplotlib 1.1.1中的pylab.ion()和程序运行时的绘图更新

python 2,matplotlib 1.1.1中的pylab.ion()和程序运行时的绘图更新

您希望该pause功能使gui框架有机会重新绘制屏幕:

import pylab
import time
import random
import matplotlib.pyplot as plt

dat=[0,1]
fig = plt.figure()
ax = fig.add_subplot(111)
Ln, = ax.plot(dat)
ax.set_xlim([0,20])
plt.ion()
plt.show()    
for i in range (18):
    dat.append(random.uniform(0,1))
    Ln.set_ydata(dat)
    Ln.set_xdata(range(len(dat)))
    plt.pause(1)

    print 'done with loop'

您无需Line2D每次都创建一个新对象,只需更新现有对象中的数据即可。

说明文件

pause(interval)
    Pause for *interval* seconds.

    If there is an active figure it will be updated and displayed,
    and the gui event loop will run during the pause.

    If there is no active figure, or if a non-interactive backend
    is in use, this executes time.sleep(interval).

    This can be used for crude animation. For more complex
    animation, see :mod:`matplotlib.animation`.

    This function is experimental; its behavior may be changed
    or extended in a future release.

一个真正的过度杀伤方法是使用matplotlib.animate模块。另一方面,如果您愿意的话,它为您提供了一种保存数据的好方法从我对[Python的回答中-1秒连续绘图。

示例api教程

python 2022/1/1 18:32:14 有204人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶