【发布时间】:2017-08-09 16:18:48
【问题描述】:
我想在循环中更新箭头位置。我发现这个post 对补丁是矩形的情况有一个类似的问题。下面,在提到的帖子中提出的解决方案添加了箭头补丁。
from matplotlib import pyplot as plt
from matplotlib.patches import Rectangle, Arrow
import numpy as np
nmax = 10
xdata = range(nmax)
ydata = np.random.random(nmax)
fig, ax = plt.subplots()
ax.plot(xdata, ydata, 'o-')
ax.xaxis.set_ticks(xdata)
plt.ion()
rect = plt.Rectangle((0, 0), nmax, 1, zorder=10)
ax.add_patch(rect)
arrow = Arrow(0,0,1,1)
ax.add_patch(arrow)
for i in range(nmax):
rect.set_x(i)
rect.set_width(nmax - i)
#arrow.what --> which method?
fig.canvas.draw()
plt.pause(0.1)
Arrow 补丁的问题在于,它显然没有像 Rectangle 补丁那样具有与其位置相关的 set 方法。欢迎任何提示。
【问题讨论】:
标签: python python-2.7 matplotlib