Animations With matplotlib

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

I think you forgot mentioning about installing the necessary moviewriter (ffmpeg)

rizkimardian
Автор

I am getting an error on the line

video = anim.to_html5_video()

Can we do it without converting it to HTML5, like a normal plot, I don't need to save it, I just need to run it and display

mohd.farhanhassan
Автор

Amazing tutorial btw a lot of other tutorials just write code and expect you to understand but you actually explain!

kainpmn
Автор

I just wish someone would tell me how to make a animation of a straight line growing not a sine.

kainpmn
Автор

very clear and concise, much better than other tutorials on the subject°

julians.
Автор

Thanks for the brief tutorial. Hope you live a good life :)

mapanjiwicaksono
Автор

Hey! Thanks a lot for the amazing video. Can you please make a video on how to do this for 3d plots in matplotlib? It would really be helpful

BaibhavSrivastaw
Автор

I'd like for one process to receive data from the serial port, and then push that data into a queue so that matplotlib can update the figure real-time!

However, FuncAnimation is not automatically calling the update function I've specified.
animation.FuncAnimation(plt.gcf(), func=self.animate_fig(), interval=100, blit=True, repeat=True)

The figure opens, but do you see anything that is preventing the call to "animate_fig"? I don't see the periodic "Update" print statement!


from time import time, sleep
from multiprocessing import Queue as mpQueue
import matplotlib.pyplot as plt
import matplotlib.animation as animation

global ani #### Must be assigned to a global variable

class PlotClass:
# Create STATIC LOCAL instances accessible across class functions
fig = None
ax = None
line1 = None
q = None
x_list_vec = []
y1_list_vec = []

def __init__(self, qdata ):
# Save handle to Queue
self.q = qdata

# this is the call to matplotlib that allows dynamic plotting
plt.ion()

# Setup Figure with 'size' number of elements
self.fig = plt.figure(figsize=(13, 6))
self.ax = self.fig.add_subplot(111)

# Create a list variable to the animation
self.line1, = self.ax.plot(self.x_list_vec, self.y1_list_vec, marker = 'o', label='y1', color='r')

# show a starting plot
plt.xticks(rotation=45, ha='right')
plt.title('Title: Hello World')

plt.show()

def animate_fig(self, frame_num, user_arg1, user_arg2): #<<<< Never Executes after FuncAnimation!!!
print("Update") ### <--- Does not show in console!
newdata = 0
while self.q.empty() is False:
print ("Got Data!")
newdata = self.q.get()
print ( newdata )

### update figure with the last data received
self.line1.set_data(0, newdata)

### must return list when blit=True
return self.line1,

# Override the run function of Thread class
def run(self):

# Must be assigned to a global variable!
global ani
ani = animation.FuncAnimation(fig=self.fig, func=self.animate_fig, fargs=["Hi", 2], interval=100, blit=True, repeat=True)
print ("FuncAnimation started")


if __name__=='__main__':
try:
# Shared Memory
q = mpQueue()

# Start Plotter
mpInst = PlotClass( q )
mpInst.run()

# Push Data to Plotter
i = 0
while True:
q.put(i) ### <--- Data to appear in Figure
sleep(1)
i = i+1
print(".")

except KeyboardInterrupt:
print ("Keyboard Interrupt!")

bennguyen
Автор

by far best, clear and fast tutorial I have seen this handled with on YouTube... thank you

mnicp
Автор

my code not displaying in Jupyter Notebooks

jagmeetsond
Автор

Man! Great content! Thanks for the time invest in sharing knowledge with us!

HenningPhysics
Автор

Verry good video, i looked everywhere for a video explainig how to do animations on matplotlib but i didn't find any, you saved me

berkoukes-design
Автор

Thanks for that explanation, man! You're amazing

johnxisde
Автор

hey u mentioned that thr r several other fns tht helps to plot the animated grapgh other then funcanimation could u please name some coz funcanimation attribute is not responding in my system

trishnachakraborty
Автор

Finally found a tutorial that works! Thanks a lot!

wenhanzhou
Автор

Post relevant code in description or link to it so that we dont have to copy it manualy.

Thanks, great job man, will follow.

alexcros
Автор

Thanks for the nice tutorial!
One issue though: I tried the code and got an error message:
RuntimeError: The animation function must return a sequence of Artist objects.
I had to add "return line, " to the end of the animate(frame) function - then it works.
Why does this not produce an error in your code?.

michaelk
visit shbcf.ru