I have the following code snippet:
import numpy as np
import matplotlib.pyplot as plt
N = 25
M = 10
def aFuncation(x):
return np.random.normal(100*np.exp(-x), 10.0)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = np.zeros(N)
ys = np.zeros(N)
stds = np.zeros(N)
for n in range(N):
avgC = np.zeros(M)
for m in range(M):
Cost = aFuncation(n)
avgC[m] = Cost
xs[n] = n
ys[n] = np.mean(avgC)
stds[n] = np.std(avgC)
# Plot the time series
ax.clear()
ax.fill_between(xs[:n], ys[:n] - stds[:n], ys[:n] + stds[:n], alpha=0.3, color='black')
ax.plot(xs[:n], ys[:n], color='red')
ax.set_xlim([0, N + 1])
ax.set_xlabel('Number of evolutions')
ax.set_ylabel('Expected future cost')
plt.show()
I am not sure why the plot is not updated after the first iteration (n=1
). I have read several posts related to this topic. The posts suggest the use of plt.ion()
, plt.clf()
, plt.draw()
, etc. Whenever more I read about this topic, I become more confused. I am unfortunately unable to find a solution to this problem.