I'm writing code that processes data from a MongoDB collection in windows, and with each of these windows, it generates a graph as seen in the graph() function below. It then returns the graph via the "return ax" line, and adds it to the "plots" list. This occurs over and over again, so by the time we get to the update function, the plots list has a bunch of axes subplot objects. Then the FuncAimation function calls update(frame), and with each iteration of it, we go down the plots list. Ideally this is supposed to give a dynamic, animated graph. When I run this, though, on pycharms I just get all len(plots) plots in separate windows instead of the animated plot
This is the code I have so far:
def graph(speed_lst):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
sns.kdeplot(data=speed_lst, ax=ax, color="palevioletred", fill=True)
return [ax]
plots = []
# bulk of code reading in collection and processing it
fig, ax = plt.subplots(1,1)
def update(frame):
global ax
ax.clear()
ax = plots[frame]
return ax
ani = animation.FuncAnimation(fig, update, frames=len(plots), interval=100, blit=True)
plt.show()
I have tried different combinations of having ax as an argument for update(frame, ax), a different combination of having return or no return values for each of my two functions, etc, as well as running the file on my terminal, and all of them yield the same result.