|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
matplotlib绘制动画,如何在显示图中,直接通过文本框输入 数值给 变量y ?
而不是 代码中的一段函数? y = np.sin(2 * np.pi * (x - 0.01 * i))
- import numpy as np
- from matplotlib import pyplot as plt
- from matplotlib import animation
- # First set up the figure, the axis, and the plot element we want to animate
- fig = plt.figure()
- ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
- line, = ax.plot([], [], lw=2)
- # initialization function: plot the background of each frame
- def init():
- line.set_data([], [])
- return line,
- # animation function. This is called sequentially
- # note: i is framenumber
- def animate(i):
- x = np.linspace(0, 2, 1000)
- y = np.sin(2 * np.pi * (x - 0.01 * i))
- line.set_data(x, y)
- return line,
- # call the animator. blit=True means only re-draw the parts that have changed.
- anim = animation.FuncAnimation(fig, animate, init_func=init,
- frames=200, interval=20, blit=True)
- #anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
- plt.show()
复制代码
参考:https://stackoverflow.com/questions/21197728/embedding-a-matplotlib-animation-into-a-tkinter-frame
第二个人Victor的回答,可以解决你的问题。
|
|