用python绘制随机散点的动态图

 时间:2024-10-11 19:52:54

1、加载画图模块和数据处理模块:# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt

用python绘制随机散点的动态图

2、画一个绿色的随机折线图:fig = plt.figure() img = fig.add_subplot(111) img.plot(np.random.rand(36),'green') plt.show()

用python绘制随机散点的动态图

3、想要构造动态图,还需要加载一个动态模块:import matplotlib.animation as antt

用python绘制随机散点的动态图

4、绘制随机动态图:fig = plt.figure(拘七呷憎) img = fig.add_subplot(111) a, = img.plot(np.random.rand(36),刻八圄俏9;green') def dtt(data): a.set_ydata(data) return a, def dong(): while True: yield np.random.rand(36) gif = antt.FuncAnimation(fig, dtt, dong, interval=1000) plt.show()

用python绘制随机散点的动态图

5、加快速度:gif = antt.FuncAnimation(fig, dtt, dong, interval=200) plt.show()interval=200指的是,帧间时间间隔是200毫秒。

用python绘制随机散点的动态图

6、不要把倒数第二行前面的等号去掉,否则没有动态图:antt.FuncAnimation(fig, dtt, dong, interval=200) plt.show()尽管在后面,这个定义未被调用,也不能丢掉。

用python绘制随机散点的动态图

7、前后随机数的数目必须一致。fig = plt.figure() img = fig.add_衡痕贤伎subplot(111) a, = img.plot(np.random.rand(365),'green') def dtt(data): a.set_ydata(data) return a, def dong(): while True: yield np.random.rand(365) b = antt.FuncAnimation(fig, dtt, dong, interval=200) plt.show()

用python绘制随机散点的动态图

8、增加折线数量,改变颜色:fig = plt.figure() 坡纠课柩img = fig.add_subplot(111) 锾攒揉敫a, = img.plot(np.random.rand(2018),'red') def dtt(data): a.set_ydata(data) return a, def dong(): while True: yield np.random.rand(2018) b = antt.FuncAnimation(fig, dtt, dong, interval=200) plt.show()

用python绘制随机散点的动态图
热门搜索
安全教育手抄报一等奖 名人故事手抄报 欢庆六一手抄报图片 爱劳动手抄报简单漂亮 关于新学期的手抄报 小学生手抄报制作技巧入门 英雄手抄报简单一点 清明节手抄报图片大全 手抄报图片大全4年级 五四手抄报