Reputation: 1063
I can't seem to find any solution to the problem I have, so I'll post a question, even though it seems like there should be a simple solution somewhere.
I want to use a live plot in tkinter and found matplotlib animation to be the best solution. However, I want the plot to update on specific lines in the code. Is there a way to do this? (Not based on an interval)
f = Figure(figsize=(5,4), dpi=100)
def animate(i):
a.plot(lidarX, lidarY, '.g', markersize = 0.5)
ani = animation.FuncAnimation(f, animate, interval=1000)
# Code to add the figure to a FigureCanvasTkAgg and pack it to the gui
Thanks in advance.
Upvotes: 1
Views: 1491
Reputation: 40737
It's a bit unclear what you mean by "to update on specific lines in the code", some more details could be useful.
In any case, FuncAnimation
is designed to update a plot at a specific interval, so if that's not what you want to do, the best strategy is to not use FuncAnimation.
You can easily update your plot "manually" by calling
def animate(i):
a.plot(lidarX, lidarY, '.g', markersize = 0.5)
fig.canvas.draw_idle()
Upvotes: 2