각 새주기 (파일 00.csv :는 매번 후자의 두 값을 추출하는 다른 파일을 읽은 결과입니다)마다 업데이트 할 수있는 "00.csv"파일이 있습니다. 여기 matplotlib를 사용하여 다른주기 후에 그래프 (애니메이션 그래프)를 업데이트/새로 고치는 방법은 무엇입니까?
는 00.csv 파일입니다. 그래프 애니메이션을 그리기 위해,0, -1184.645675411964
1, -1184.653778859924 # first cycle
2, -1184.657325034754 # second cycle
3 -1184.657972735058
4, -1184.658582481392
5, -1184.658800896487
6, -1184.658844384850
7, -1184.658846846248
8, -1184.658825508352 # eighth cycle
내가 간단한 스크립트를 만들어
import matplotlib.pyplot as plt
from matplotlib import style
import matplotlib.animation as animation
fig = plt.figure()
ax1 = fig.add_subplot(111)
def animate(i):
graph_data = open('00.csv', 'r') .read()
lines = graph_data.split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 1:
x, y = line.split(',')
xs.append(x)
ys.append(y)
ax1.clear()
ax1.plot(xs, ys , color='blue', linestyle='dashdot', linewidth=4, marker='o', markerfacecolor='red', markeredgecolor='black',markeredgewidth=3, markersize=12)
ani = animation.FuncAnimation (fig , animate, interval=1000)
#plt.legend(loc='upper right', fancybox=True)
plt.savefig("Plot_SCF-Energy_.pdf", dpi=150)
plt.savefig("Plot_SCF-Energy_.png", dpi=150)
plt.show()
어느 순간에 그 결과 (: 1/8주기)은 다음과 같습니다. ,210
내 문제이다 여덟 번째 사이클 이후 다른 사이클 (말 : 열 모두 X, Y)를 첨가 이런 파일 00.csv하기 :
9, -1184.658861339248 # ninth cycle
10, -1184.658863735214 # tenth cycle
11, -1184.658862250518 # eleventh cycle
을하지만 그래프 여덟째 냉동 유지 사이클, 그것은 업데이 트되지 않습니다! ???
나는 또한 Matplotlib create real time animated graph을 따라 갔지만 문제를 해결하지 못했습니다.
그래프를 새로 고침하기 위해 새주기 후에 00.csv 파일을 자동으로 읽는 방법이 있습니까 ??
감사합니다. 스크립트를 사용해 보았지만 동일한 결과를 얻었습니다. 이 시도 후에 나는 문제가 그래프를 그리는 것에 초점을 맞추지 않는다는 것을 깨달았지만 그것이 나의 파일 00.csv에 관한 것입니다. "00.csv"가 자동으로 업데이트되지 않는다는 것을 알았 기 때문에. –