一旦动画图表中发生更改,如何更新刻度标签?
这只是我需要的一个简单示例。我意识到我可以设置 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()
最佳答案
我让它与建议的猴子补丁一起工作in this post.
希望这对那些花了很多时间试图解决这个问题的流浪灵魂(像我一样)有用。
关于python - 如何更新动画 matplotlib 图中的刻度标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42258745/