나는이 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
,174,515을
변경되지 않습니다 플롯 창에서 다른 데이터가 있기 때문에 나는 모든 것을 replot하는 "바보"방법을 피하기 위해 싶습니다이 정말 느린 제 1 단계로
# 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()
나는
- 은 (지정된 연결로 포인트를 플로팅) 초기 문제의 해결 방법에 대한 내을위한 루프
- 아이디어보다 더 나은 솔루션을 함께 가자 ... 방법을 제안 찾고 있어요 더 우아한 방법