python - 如何更新动画 matplotlib 图中的刻度标签

标签 python matplotlib

一旦动画图表中发生更改,如何更新刻度标签? 这只是我需要的一个简单示例。我意识到我可以设置 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/

相关文章:

python - 修改Keras中的图层参数

python - 在 Amazon 的 DynamoDB 中编写分布式队列

python - matplotlib 轮廓可以匹配像素边缘吗?

opencv - 为什么 pyplot.imshow() 改变数组中的颜色 channel

python - Json/奇怪的列转换

python - 调用序列化器的 post 方法并向其传递数据

python - 在 Python 中使用 "continue"语句的示例?

python - Matplotlib 和 django 模板

python - pandas.plot(...) 意外反转 x 轴

python - python3 pandas 中的时间轮