[英]How to update tick labels in animated matplotlib graph
How can I get the tick labels to update once changed in an animated graph?一旦在动画图形中更改,如何让刻度标签更新? Here is just a simple example of what I need.
这只是我需要的一个简单示例。 I realize I can set
blit=False
and have it work, however the project I am working on requires blit=True
for performance reasons.我意识到我可以设置
blit=False
并让它工作,但是我正在处理的项目出于性能原因需要blit=True
。
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
import time
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x + i/10.0))
if i > 30:
ax.tick_params(axis='y', colors='red') ### How do I get my graph to reflect this change?
return line,
def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
interval=100, blit=True)
plt.show()
I got it working with the monkey patch suggested in this post.我让它与这篇文章中建议的猴子补丁一起工作。
Hope this works for wandering souls (like me) that spent A LOT of time trying to solve this problem.希望这对花了很多时间试图解决这个问题的流浪灵魂(像我一样)有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.