python matlabplot animate 刷新_python – Matplotlib animate不会更新刻度标签

我试图通过使动画运行增加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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值