matplotlib.pyplot怎么显示动图

动画显示方式

在matplotlib.pyplot 中

inline只显示图片

notebook可以显示动画

tk显示窗口

%matplotlib notebook
# -*- coding: utf-8 -*-   
  
import numpy as np  
import matplotlib.pyplot as plt  
import matplotlib.animation as animation  
  
fig = plt.figure()  
axes1 = fig.add_subplot(111)  
line, = axes1.plot(np.random.rand(10))  # 注意这里有点逗号
  
#因为update的参数是调用函数data_gen,所以第一个默认参数不能是framenum  
def update(data):  
    line.set_ydata(data)  
    return line,  
# 每次生成10个随机数据  
def data_gen():  
    while True:  
        yield np.random.rand(10)  
  
ani = animation.FuncAnimation(fig, update, data_gen, interval=2*1000)  
#plt.show()  
<IPython.core.display.Javascript object>

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44510615/article/details/89297455