我试图通过使动画运行增加x值来修改和示例.我想更新x轴刻度标签以根据x值更新.
我试图在1.2中使用动画功能(特别是FuncAnimation).我可以设置xlimit但是tick标签没有更新.我也尝试明确设置刻度标签,但这不起作用.
我看到了这个:Animating matplotlib axes/ticks和
我试图在animation.py中调整bbox,但它没有用.我对matplotlib相当新,并且对于解决这个问题的实际情况不太了解,所以我将不胜感激任何帮助.
谢谢
"""
Matplotlib Animation Example
author: Jake Vanderplas
email: vanderplas@astro.washington.edu
website: http://jakevdp.github.com
license: BSD
Please feel free to use and modify this, but keep the above information. Thanks!
"""
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(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
def animate(i):
x = np.linspace(i, i+2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
ax.set_xlim(i, i+2)
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)
plt.show()
解决方法:
简单的答案是删除blit = True
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20)
如果你有blit = True,那么只有已经改变的艺术家被重新绘制(而不是重新绘制所有的艺术家),这使渲染更有效率.如果艺术家从更新功能返回(在本例中为动画),则将其标记为已更改.另一个细节是艺术家必须在轴边界框中使用代码在animation.py中的工作方式.请参阅顶部的一个链接,了解如何处理此问题.
标签:python,matplotlib,animation,plot
来源: https://codeday.me/bug/20190901/1782446.html