I have a file "00.csv", which can be updated each new cycle (the file 00.csv: is the result of a reading of another file, which extracts to the latter two values each time (each cycle).
here is the 00.csv file:
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
I created a simple script, in order to draw a graph animate.
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()
the result (at a certain moment: eighth cycle) is as follows:
my problem is: after the eighth cycle, other cycles are added (i mean: both columns x, y) to 00.csv file like this:
9, -1184.658861339248 # ninth cycle
10, -1184.658863735214 # tenth cycle
11, -1184.658862250518 # eleventh cycle
but the graph remains frozen in eighth cycle, it does not update !! ???
in addition,I followed Matplotlib create real time animated graph, but I did not solve my problem.
Is there a way to automatically read the file 00.csv after new cycle, in order to refresh my graph ??