私はこのquestionに似た質問がありますが、非常に多くのポイントをプロットするのではなく、ポイントとエッジの数を少なくして(少なくとも10因子)、アニメーションしたいそれら。具体的には、それが進化し、変形平方latticのように見える2Dマップとコホーネンネットワークの可視化である、ウィキペディアからこの画像を参照してください。this答えからコードを撮影エッジで結ばれたポイントのグラフをアニメ化する
ビットを変更し、最小の例は次のようになります
import numpy as np
import matplotlib.pyplot as plt
def getXY(points, edges):
"""Return x and y arrays to pass to the plot function"""
return [points.T[i][edges.T] for i in np.arange(points.shape[1])]
points = numpy.array([[1,2],[4,5],[2,7],[3,9],[9,2]])
edges = numpy.array([[0,1],[3,4],[3,2],[2,4]])
lines = plt.plot(*getXY(points, edges), linestyle='-', color='y',
markerfacecolor='red', marker='o')
plt.show()
そして、更新ポイントの座標を変更する起こる:
points += 1 # simplified version of a real update
変更されませんプロットウィンドウ内の他のデータがあるので、私は、すべてを再プロットする「愚かな」道を避けたい、また、これは本当に遅いです:最初のステップとして
# repeat after each update all the calculation
plt.cla()
x, y = [points.T[i][edges.T] for i in np.arange(points.shape[1])]
lines = plt.plot(x, y, linestyle='-', color='y',
markerfacecolor='red', marker='o')
plt.show()
、私が保存されて変数lines
の初期プロットから作成されたLine2Dデータ 私が今直面している問題は、私がラインデータを更新したい場合、私が思いつくことができる唯一の解決策は、私にはあまりエレガントではないすべてのラインを繰り返し処理する必要があるということです:
x, y = getXY(points, edges)
if len(lines) > 1:
for i, d in enumerate(zip(x.T, y.T)):
lines[i].set_data(d)
else: # has to be treated seperately, since the format of x and y is different
lines[0].set_data(x, y)
plt.show()
私は
- は、初期の問題を解決する方法についての私のforループ
- アイデア(指定した接続でのポイントをプロット)より良い解決策を考え出すどのように...提案を探しています
よりエレガントな方法