如何在同一张图上的多个动画之间创建延迟(matplotlib,python) [英] How to create a delay between mutiple animations on the same graph (matplotlib, python)

查看:88
本文介绍了如何在同一张图上的多个动画之间创建延迟(matplotlib,python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是上一个问题的参考

解决方案

您可以将步数增加一倍,首先绘制第一条曲线,然后绘制另一条曲线.

 将numpy导入为np导入matplotlib.pyplot作为plt导入matplotlib.animation作为动画x = np.arange(130,190,1)y = 97.928 * np.exp(-np.exp(-0.1416 *(x-146.1)))z = 96.9684 * np.exp(-np.exp(-0.1530 *(x-144.4)))无花果,ax = plt.subplots()line1,= ax.plot(x,y,color ="r")line2,= ax.plot(x,z,color ="g")def更新(num,x,y,z,line1,line2):如果num<len(x):line1.set_data(x [:num],y [:num])line2.set_data([],[])别的:line2.set_data(x [:num-len(x)],z [:num-len(x)])返回[第1行,第2行]ani = animation.FuncAnimation(fig,update,2 * len(x),fargs = [x,y,z,line1,line2],间隔= 295,blit =真)ax.set_xlabel('年龄(天)')ax.set_ylabel('EO(%)')plt.show() 

This is a reference from a previous question

two lines matplotib animation

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

x = np.arange(130, 190, 1)
y = 97.928 * np.exp(- np.exp(-  0.1416 *( x - 146.1 )))
z = 96.9684 * np.exp(- np.exp(-0.1530*( x - 144.4)))

fig, ax = plt.subplots()
line1, = ax.plot(x, y, color = "r")
line2, = ax.plot(x, z, color = "g")

def update(num, x, y, z, line1, line2):
    line1.set_data(x[:num], y[:num])
    line2.set_data(x[:num], z[:num])
    return [line1,line2]

ani = animation.FuncAnimation(fig, update, len(x), fargs=[x, y, z, line1, line2],
              interval=295, blit=True)

ax.set_xlabel('Age (day)')
ax.set_ylabel('EO (%)')

plt.show()

I want to plot the graph such that, it first animates the green line, then the orange line.

Currently it animates both the line together.

解决方案

You could make the number of steps twice as long, first draw the first curve and then the other one.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

x = np.arange(130, 190, 1)
y = 97.928 * np.exp(- np.exp(-  0.1416 * (x - 146.1)))
z = 96.9684 * np.exp(- np.exp(-0.1530 * (x - 144.4)))

fig, ax = plt.subplots()
line1, = ax.plot(x, y, color="r")
line2, = ax.plot(x, z, color="g")

def update(num, x, y, z, line1, line2):
    if num < len(x):
        line1.set_data(x[:num], y[:num])
        line2.set_data([], [])
    else:
        line2.set_data(x[:num - len(x)], z[:num - len(x)])
    return [line1, line2]

ani = animation.FuncAnimation(fig, update, 2 * len(x), fargs=[x, y, z, line1, line2],
                              interval=295, blit=True)

ax.set_xlabel('Age (day)')
ax.set_ylabel('EO (%)')
plt.show()

这篇关于如何在同一张图上的多个动画之间创建延迟(matplotlib,python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆