High FPS animations in matplotlib

Поділитися
Вставка
  • Опубліковано 23 жов 2024
  • See how blitting can be used to increase a matplotlib animation's fps by over 7x.
    matplotlib is a plotting library for python, that produces publication quality plots. Unfortunately because they are publication quality, the time taken to set-up and draw the plot can be quite slow.
    Typical animation framerates for redrawing plots are in the low/sub 10s. By using the FuncAnimation class along with blitting framerates over 60 fps are achievable.
    This video is aimed at undergraduates or anyone interested in python.

КОМЕНТАРІ • 24

  • @curious9
    @curious9 2 роки тому +10

    Thanks, really good explanation! I was trying to improve animation performance myself in the last days, and one thing worth mentioning is that blitting works only with interactive backends, but if you are saving it to a movie it silently reverses to full redraw, which is not documented in FuncAnimation nor Animation classes, and it took me some time to realize by studying sources and debugging. So in that case you need to implement it yourself not relying on FuncAnimation.

    • @evancarpenter
      @evancarpenter 2 роки тому +1

      Wait really‽‽‽ That is some really good information!! Thank you so much for commenting this :)

  • @imotvoksim
    @imotvoksim Рік тому +1

    Very nice overview, thanks a lot! My takeaway: fix the limits of axes to fit the final plot since the first frame and just blit away 😅

  • @Rwop81
    @Rwop81 2 роки тому +19

    It's great...could you please share the python code?

  • @originuk
    @originuk Рік тому

    Nice to see how you went through the journey... Look at this... .. but if you do it this way ..... So yeah, don't get the UI to plot/scale ... and it's REALLY quick!

  • @randacoustics9269
    @randacoustics9269 2 роки тому

    Great video. Very informative for the tradeoffs of the different approaches!

  • @johnteran8889
    @johnteran8889 Рік тому

    For something like a simple count you can use a text object inside the canvas and update that.

  • @fergusjohnstone7604
    @fergusjohnstone7604 2 роки тому +7

    Also what is the function getfigax()? can't seem to find documentation on it

  • @t.p.2305
    @t.p.2305 10 місяців тому

    Thank you, very useful!

  • @fergusjohnstone7604
    @fergusjohnstone7604 2 роки тому +1

    Great vid cheers. Would the fps be improved by updating more than one line at a time. Currently need to plot sensor data that comes in every 13.5ms but it occured to me i could maybe plot two data points every 27ms? Would this work? I realise it may look less smooth but this way it would only require 37fps to stay real-time right?

  • @stevehageman6785
    @stevehageman6785 Рік тому

    Great information, thanks for sharing!

  • @electron46
    @electron46 5 місяців тому

    Thank you for your excellent video. On line 103 of your code, is shows lineL.set_data(t[frame], y[frame]) where frame is a single number from range(N). This produces an error. Please tell us why your code functions. Thank you!

  • @lameiraangelo
    @lameiraangelo 2 роки тому +1

    This is great.

  • @rajatmond
    @rajatmond Рік тому

    Very invaluable and instructive video. I am making an automatic data logging device using a raspberry pi for my gf for her research work and I was searching for exactly this.
    Btw, any idea on how to decouple the data processing logic from the matplotlib gui? I really need to offload the data processing task to a different thread because it hangs the gui and the timings are way off. It is usually advised not to put time consuming code in gui event callbacks (here the events are probably some kind of timer events).

    • @Glanmire3
      @Glanmire3 Рік тому

      I'm not a pro so my idea might not suits for you. I'm doing something like that. What I decided, I write the logged data in live to a csv file along with a timestamp so generate a graph I don't really need during the recording. (a device insert into a slot and the force recorded from a weight sensor readings). Because it's a .csv file easy to process later on even with excel.

  • @theopaltarot
    @theopaltarot 2 місяці тому

  • @seokjinchung3694
    @seokjinchung3694 Рік тому +1

    We want the code!!!!!!!!!!!!!! great thing : ) 🤧

  • @aspuser1081
    @aspuser1081 Рік тому

    With animtion

  • @punjaramborhade1701
    @punjaramborhade1701 Рік тому

    Friend where is code???
    So we can try by our too...

    • @kychemclass5850
      @kychemclass5850 Рік тому +4

      The code is in the video. The info Dave's Space shared is more than valuable enough for you to pause the video and write out the code manually. Like in the good old 80's computing days, and the code blocks aren't too big.

    • @Glanmire3
      @Glanmire3 Рік тому

      @@kychemclass5850 You right and actually type in a code more useful to learn the language than just copy/paste only.

  • @aspuser1081
    @aspuser1081 Рік тому

    How to kivy metapolt plt.gcf convert plt.show()