cor*_*a55 1 python animation matplotlib python-2.7
我一直在寻找一种方法来更改使用动画中注释的 arrowprops 参数创建的箭头的属性(matplotlib)。
箭头是这样创建的:
axes.annotate('', xy=(-1, -1), xytext=(-1, -1), xycoords='data', textcoords='data',
arrowprops=dict(arrowstyle='<-', color='blue', linewidth=2))
Run Code Online (Sandbox Code Playgroud)
我希望能够在动画期间更改箭头的颜色。
注释的箭头存储在arrow_patch属性中。您可以通过 设置它的颜色set_color。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
ax.axis([-2,2,-2,2])
arrowprops=dict(arrowstyle='<-', color='blue', linewidth=10, mutation_scale=150)
an = ax.annotate('Blah', xy=(1, 1), xytext=(-1.5, -1.5), xycoords='data',
textcoords='data', arrowprops=arrowprops)
colors=["crimson", "limegreen", "gold", "indigo"]
def update(i):
c = colors[i%len(colors)]
an.arrow_patch.set_color(c)
ani = animation.FuncAnimation(fig, update, 10, interval=1000, repeat=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)