Animating Plots In Python Using MatplotLib [Python Tutorial]

  Рет қаралды 72,026

CodingLikeMad

CodingLikeMad

2 жыл бұрын

This video shows how to make mp4 and gif (movie) files out of figures in python using matplotlib. Maximize your data visualization impact using matplotlib animation when doing data science.
FFMpeg can be downloaded here if you need it:
www.ffmpeg.org/download.html
The github repo can be found here for all the examples mentioned:
github.com/codinglikemad/pyAn...

Пікірлер: 87
@leobianco838
@leobianco838 2 жыл бұрын
I never comment on YT, but I have to say, you have an exceptional talent for teaching. Thank you for this clear explanation !
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Thankyou :)
@MrJonsi7777
@MrJonsi7777 Жыл бұрын
Brilliant, thank you! I knew that it couldn't be so hard given you can export plots as images, but this is way cleaner than any documentation I attempted to read!
@leonacndanmark
@leonacndanmark Жыл бұрын
Awesome plotting video... and even more important, really well explained! In this way you grab both the beginner and experienced audience after my opinion.
@joepvandeneijnden3226
@joepvandeneijnden3226 2 жыл бұрын
Showing how to solve the error by defining the path to ffmpeg was very helpful! Thanks a lot. :)
@ScienceGuy60223
@ScienceGuy60223 Жыл бұрын
I don't usually comment but this was an excellent tutorial, thanks for making it! Clear and straightforward, I was able to use this on a data visualization problem at work and people love being able to have their own copy of the animation I made.
@tdworz
@tdworz Жыл бұрын
You taught me a whole new way to think about data visualization animation. Fantastic vid! Thanks!
@charlihamilton4379
@charlihamilton4379 2 жыл бұрын
I've been trying to animate the evolution of a Wigner function as a surface plot for a while now and kept getting stuck but this taught me exactly how to do it! Thank you very much
@smabedi
@smabedi 8 ай бұрын
The best tutorial about animated graphs I've ever seen!
@rafiohero1
@rafiohero1 2 жыл бұрын
Best tuto ever on this topic where others are so complicated !
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Thanks so much :)
@corysechrest
@corysechrest Жыл бұрын
Definitely going to be using this as the basis to animate/plot some MLB pitches. Thanks for the tutorial!
@scuffed_content
@scuffed_content 2 жыл бұрын
I like to use ffmpeg and ffplay when testing cameras used for OpenCV. Nice job ! Keep it up.
@nicolassaintier5829
@nicolassaintier5829 Жыл бұрын
Nice and clear, just what I needed ! Thank you very much !
@baila_fuerte
@baila_fuerte Ай бұрын
You are amazing! One of the best channels out there! :) This video was great. Thank you!
@jakubscholtz3320
@jakubscholtz3320 Жыл бұрын
Thanks man, this was super helpful.
@MrMarc1991
@MrMarc1991 Жыл бұрын
Thank you for the tutorial. You have a really good teaching style, clear and easy to follow.
@unverozkol
@unverozkol Жыл бұрын
Your 3D surface plot animation in the github was saved my day. Thank you.
@unverozkol
@unverozkol Жыл бұрын
Quick Question, I've a single "for loop" that generates two outputs. And I like to make two separate mp4's with each one of them. And I only want to run this "for loop" once. how can this be done?
@dvir-ross
@dvir-ross 8 ай бұрын
Great video! Thanks
@christianburgos7961
@christianburgos7961 6 ай бұрын
This is fantastic. Thank you sir! I'll use it on my projects :)
@jucaandre
@jucaandre 9 ай бұрын
thank you! very nice explanation
@p0kepengin592
@p0kepengin592 2 ай бұрын
great video!
@AI_For_Scientists
@AI_For_Scientists Жыл бұрын
loved it thank you
@madhavsirohi2225
@madhavsirohi2225 2 жыл бұрын
Wow that was so wonderfully made! Loved it!
@Quantanalytics-fv4xx
@Quantanalytics-fv4xx 3 күн бұрын
Thank you for the very useful video, it was easy to understand
@BetterMedia
@BetterMedia 26 күн бұрын
Amazing
@denizural5390
@denizural5390 9 ай бұрын
Great video 👏👏👏 subbed
@algola7024
@algola7024 2 жыл бұрын
Thank you for this. I learned so much 😊
@TheTenorChannel
@TheTenorChannel 2 жыл бұрын
Excellent useful and clear video, I'm recommending your channel!
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Appreciate it, glad you liked it.
@shirosensei3565
@shirosensei3565 10 ай бұрын
Hi! I did the same to get the surface levels for a 4D function (f(x,y,z)=x^2+y^2+z^2, here the gif plot a family of spheres of radius R), i wonder if is possible to plot a bar that moves with the variation of R.
@electron46
@electron46 Ай бұрын
Thank you for the excellent video content. I would suggest that you use a larger font and one with greater contrast.
@G_a_n_d_u
@G_a_n_d_u 2 жыл бұрын
Many many thanks..... Please carry on❣️
@youcefyahiaoui1465
@youcefyahiaoui1465 11 ай бұрын
Truly outstanding tutorial! Thank you.
@fakhriddinostanakulov1628
@fakhriddinostanakulov1628 8 ай бұрын
It doesn`t work in Jupyter Notebook
@alireza48ify
@alireza48ify Жыл бұрын
Very nice video, thank you! I have some data files that have information such as coordinates and vector components in a mesh in a plane. These data files show evolutions of vectors (dipoles) over Monte Carlo steps. I can plot each step of course as density plot in a seaborn but it would be nice to visualize how the dipoles evolve over Monte Carlo steps. Do you have any suggestions where I need to begin? Thank you again
@estherlisiane9786
@estherlisiane9786 Жыл бұрын
How to display one point at a time, i.e point by point without keeping the past plots? So that it can display as a single moving dot?
@nenekyuu
@nenekyuu Жыл бұрын
Thank you so much, this was really helpful! I've been trying to display also the frame number on the plot (in the .gif file) but I can't really figure out how to do it. Any ideas?
@agc444
@agc444 Жыл бұрын
Great job. Thanks a lot.
@eriksteen84
@eriksteen84 Жыл бұрын
Thank you for the wonderful video!
@gustavojuantorena
@gustavojuantorena 5 ай бұрын
Best tutorial for this topic on internet
@randyyates9837
@randyyates9837 4 ай бұрын
First, excellent tutorial, thank you. Question: How would you add an audio track to the generated .mp4?
@muhammadishaq2532
@muhammadishaq2532 Жыл бұрын
@CodingLikeMad I am having trouble to graph values of two parameters generated from python code included loops with multiple if statements. each iteration generate one value of required parameter, and graphing these against the variable responsible of change in values is need! looking for help.
@pabitraranjangiri1773
@pabitraranjangiri1773 Жыл бұрын
Thank you very much for the instructions
@thebuggser2752
@thebuggser2752 6 ай бұрын
Very neat!! Thanks!!
@rooroo140
@rooroo140 Жыл бұрын
Could this be done within the Python visualization of Power Bi? I’ve been trying to use Plotly for this but that library isn’t supported.
@my-love404
@my-love404 3 ай бұрын
you deserve more subscribers ☺ ☺ ☺ ☺ 👏 👏 👏 👏
@my-love404
@my-love404 3 ай бұрын
I want to learn sir please tell me the process, I want to see mathematical equation and theorem, moving and visualization like a pro.... What to learn first and where ?
@adamcierpica9411
@adamcierpica9411 Жыл бұрын
Hey, thank you for the tutorial, anyone has an idea why PyCharm might be returning a blank frame (no values/grid no nothing) .gif file? so seems it's not even generating a first frame. Generating a static Fig. works without any problems. thank you in advance
@gedtoon6451
@gedtoon6451 11 ай бұрын
Matplotlib FuncAnimation appears to use global variables. Is there a way to put the FuncAnimation code in a main() function and call it with : if _name_ == "__main__": main()
@Kaassap
@Kaassap 11 ай бұрын
You could have just used the linspace as xlist and ran np.sin(xlist) that would have given you the vectorized versions of xlist and ylist.
@AliceShisori
@AliceShisori 9 ай бұрын
thank you bro! just what I want to learn right now :D
@frd85
@frd85 4 ай бұрын
very helpful video. thanks!
@knowledgelover2736
@knowledgelover2736 Жыл бұрын
Question. Can this be done in real time? Or does it only collect all data and then render post? Also. This explanation was insanely clear. I never really understood matolotlib until seeing this.
@CodingLikeMad
@CodingLikeMad Жыл бұрын
So the rendering itself is done as it goes. Basically what it does is render each frame of the graph and then drops it into a frame buffer. However I believe it does not encode until the end when it saves. From a practical perspective though, for 60 fps it will take longer to run the script than the final video is. If you wanted matching speeds you'd either need to further optimize or set a lower fps for the output I think. I havent timed it, but I believe for most graphs I would do this with, it will take longer than the 8 or 16 ms per frame I'd want to look real time.
@francoiswessels8062
@francoiswessels8062 2 жыл бұрын
simplest=most_powerful
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Sometimes it to be that way :)
@sidddddddddddddd
@sidddddddddddddd 2 жыл бұрын
I have a function graph(num) where num ranges from 0 to 1000. It returns x and y list for each value of num. Now, I tried running this: with writer.saving(fig, "plot.gif", 100): for num in range(0, 1000+1): x, y = graph(num) l.set_data(x, y) writer.grab_frame() But it throws me the error: list index out of range. Could you help me with this, why do I have this error?
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Which line throws that error? If it is l.set I'd guess your x and y are not the same length. I'd check the content of x and y first.
@mohamedunknown871
@mohamedunknown871 Жыл бұрын
Thanks for the video. I am only seeing a plot of the wave with no animation. Would you know why that is? Below is my code. import matplotlib.pyplot as plt import numpy as np from matplotlib.animation import PillowWriter fig = plt.figure() l,= plt.plot([], [], 'k-') plt.xlim(-5, 5) plt.ylim(-5, 5) def func(x): return np.sin(x) metadata = dict(title='Movie', artist='test') writer = PillowWriter(fps=15, metadata=metadata) xlist = [] ylist = [] with writer.saving(fig, "sinWave.gif", 100): for xval in np.linspace(-5,5,100): xlist.append(xval) ylist.append(func(xval)) l.set_data(xlist, ylist) writer.grab_frame()
@gotuki7889
@gotuki7889 Жыл бұрын
I have a question : what if we want to create a video from matrixes that we convert into images ? Is it the same idea ?
@CodingLikeMad
@CodingLikeMad Жыл бұрын
As long as the matrix display is done through matplotlib, it should be the same, yep. I havnt tested it, but I assume it will work for you.
@tofumakesvideos
@tofumakesvideos 28 күн бұрын
Hello, is it possible to feed live data to the program and plot it with your method sir? Thank you.
@CodingLikeMad
@CodingLikeMad 22 күн бұрын
With sufficient work, yes. But itd be pretty round about I think.
@hanzo52
@hanzo52 Жыл бұрын
What if you have an xcel sheet with x and y values you want to animate with gif?
@CodingLikeMad
@CodingLikeMad Жыл бұрын
Export it to a csv, then load it from python using something like readcsv()
@arunsebastian4035
@arunsebastian4035 2 жыл бұрын
hi sir this video is great but when i try to do this i got an error in google colab as "List index out of range " can you help me how to solve that
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Can you say where the error occurs?
@risottoyagami4151
@risottoyagami4151 11 ай бұрын
Then there's no point of buying Tableau or Power BI for data visualization; you truly are a genius.
@ym9849
@ym9849 Жыл бұрын
👌👌
@daddy_myers
@daddy_myers 2 жыл бұрын
Hey Mad! I tried using your code today; but unfortunately, it keeps giving me the error message:"invalid command name .!canvas" on the "writer.grab_frame()" line. Could you please tell me why that error is popping up and how I could solve it? The plot does work sometimes when I edit a couple random snippets of the code; but it's either a blank or a stationary plot with only the black sine function plotted, and sometimes it wouldn't even show the figure tab! - I couldn't manage to make it show an animated plot at all. Also, I'm using an exact copy of your code which I got off your github link; so I'm sure there are no typos on my side. Thanks in advance!
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
Weird, I'll look into it. Havent seen that before.
@daddy_myers
@daddy_myers 2 жыл бұрын
@@CodingLikeMad Keep me updated!
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
@@daddy_myers So I don't have a guaranteed answer for you, but a bit of research shows me that this error is likely due to the tk window being closed somehow. Basically it looks for the window to grab the frame from, and then it can't find it. A few different things come to mind - one being that your computer is possibly underpowered for rendering and the window object isn't fully initialized when the frame grab is called. Another possibility is that there is an issue with tk window setup, perhaps the render engine itself isn't callable. Can you normally plot graphs well? Is it possible your computer is under powered for this? Just two guesses. In the former case you'd need to setup your libraries correctly, while in the latter case I'd suggest throwing a loop with a 'try...except' around the frame grab, and then having it wait a second and trying again for 5 or 10 seconds total time before giving up on the frame. BTW, does it fail on the first frame of the video, or later on?
@daddy_myers
@daddy_myers 2 жыл бұрын
@@CodingLikeMad I'm pretty sure it's not about my computer, since I can plot graphs just fine - and I managed to make a perfectly operating animated plot yesterday using a different code; so that's not to blame. As for the second question, the plot mostly fails to be projected at all; meaning I just get clear, blank axes.
@kychemclass5850
@kychemclass5850 Жыл бұрын
Tq.
@naturfagstoff
@naturfagstoff Жыл бұрын
Cool! Can You give an example of trapezoid integration?
@GoCoding-vd9k
@GoCoding-vd9k 6 ай бұрын
nice matplotlib 🙂
@takayush6313
@takayush6313 Жыл бұрын
Wish u were my teacher :]
@knowledgelover2736
@knowledgelover2736 Жыл бұрын
This was awesome but when is the next Mistborn book coming out?
@YTUsed
@YTUsed Жыл бұрын
Codes are literally 2px on my phone lol
@CodingLikeMad
@CodingLikeMad Жыл бұрын
Yeah, I'd recomend not looking at code on your phone :p
@davidmurphy563
@davidmurphy563 6 ай бұрын
As simple as that. Nice explanation. Question, Mad... Is your full name Madison?
@carlosdavid4193
@carlosdavid4193 2 жыл бұрын
Thanks for your tutorial. But, please, zoom your screen.
@CodingLikeMad
@CodingLikeMad 2 жыл бұрын
For this tutorial I had increased the font size in pycharm to make things more visible, I'll look into improving viewability more. Thanks for the feedback :)
How I make science animations
43:39
Artem Kirsanov
Рет қаралды 697 М.
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 29 МЛН
Me: Don't cross there's cars coming
00:16
LOL
Рет қаралды 13 МЛН
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 48 МЛН
Tom & Jerry !! 😂😂
00:59
Tibo InShape
Рет қаралды 65 МЛН
Seaborn Is The Easier Matplotlib
22:39
NeuralNine
Рет қаралды 162 М.
Let's code 3D Engine in Python from Scratch
14:55
Coder Space
Рет қаралды 377 М.
Animations With matplotlib
18:49
Physics With Nero
Рет қаралды 40 М.
7 Python Data Visualization Libraries in 15 minutes
15:03
Rob Mulla
Рет қаралды 71 М.
Making Animations in Python using Matplotlib!
22:05
Younes Lab
Рет қаралды 7 М.
Make Videos Like 3Blue1Brown | Manim
9:32
Darwin Tech
Рет қаралды 151 М.
Мой инст: denkiselef. Как забрать телефон через экран.
0:54
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 5 МЛН
GamePad İle Bisiklet Yönetmek #shorts
0:26
Osman Kabadayı
Рет қаралды 603 М.
Что еще за съемные фронталки от Vivo? #vivo
0:41