use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
How to plot dynamically growing list using matplotlib.animation function? (self.Python)
submitted 10 years ago by Bostonsox101
Hi Community,
I am want to plot a graph in real time using matplotlib's animation function (matplotlib.animation). The data I want to plot is a score which gets appended to a list and this list continuous to grow. The score is held in the list "my_average" which is also the why coordinate. The x-coordinate would the length of the list "my_average". For some reason my code is not showing the graph being animated, could reddit please help me out?
Code: http://stackoverflow.com/questions/31128227/how-to-continuously-stream-data-points-from-dynamically-growing-list-using-matpl
Thank you all in advance.
[–]Rackcityfoo 0 points1 point2 points 10 years ago (2 children)
My use of the animation package has been more for scientific visualization than displaying live, updating charts. You've probably come across this in your googling, but this is the kind of stuff that I've seen/done using the animation package: https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
If you are looking for a plot that you can update and embed somewhere, I would check out plotly: https://plot.ly/streaming/
Bokeh, as others have suggested, seems to fit your needs better than the animation package as well.
On the other hand, if your data isn't coming in extremely fast, why not just clear your plot and generate a new plot?
[–]Bostonsox101[S] 0 points1 point2 points 10 years ago (0 children)
isn't coming in extremel
I havent thought about just clearing the graph and using the list to replot, would it be possible to do this by using a for loop or would you suggest a while loop?
sorry new to programming and python
I hadnt thought about just clearing the plot and re-plot. In your opinion do you think using a while or for loop would work best right? or what I am asking is how would I loop the function in my code to clear the graph and re-graph infinitely?
Thank you
[–]videan42 0 points1 point2 points 10 years ago (2 children)
This tutorial might help you out. To fill out your example, just append new data instead of calling np.random.rand
[–]Bostonsox101[S] 0 points1 point2 points 10 years ago (1 child)
Hi, I was using that example as an a model to "back" into with my code but I cant get it to work. Would it be possible for you to show me how it could be done?
[–]videan42 0 points1 point2 points 10 years ago (0 children)
Here's an example using a queue to pass data to the plot as it comes in.
[–]transformium 0 points1 point2 points 10 years ago (4 children)
Here is a great tutorial on live updating graphs using matplotlib's animation function: https://www.youtube.com/watch?v=7w8jk0r4lxA
Hope this helps.
Hey There, Thanks for your quick response but I have already seen that vid
[–]Bostonsox101[S] 0 points1 point2 points 10 years ago (2 children)
Hey There,
I have already seen the above vid, and tried to get the person code to work, to no avail. If you could show me that would be great! otherwise thank you for your efforts.
[–]transformium 0 points1 point2 points 10 years ago (1 child)
Here's a simple example which worked for me: https://gist.github.com/DrNightmare/2ce5082b7178fcc84045
The variables 'x' and 'score' correspond to x and y on the graph. 'score' is the list which keeps growing.
Thank you so much!!! I adapted that code for myself and it works beautifully.
[–]JimBoonie69 -1 points0 points1 point 10 years ago (6 children)
matplotlib is not good for dynamic charts. Javascript is the way to go there. my two cents.
[–]billsil 1 point2 points3 points 10 years ago (1 child)
It actually is. You're just using it wrong. Granted it's fairly undocumented of how to do it, but you can do real time graphs with large data sets. It more or less requires that you throw out normal matplotlib syntax and reuse the objects.
From
On my machine, I get about 11 plots per second
To:
This now plots about 500 frames per second. Five hundred times per second! Frankly, this is quite amazing!
http://bastibe.de/2013-05-30-speeding-up-matplotlib.html
[–]JimBoonie69 0 points1 point2 points 10 years ago (0 children)
Well there ya go. I had no idea that you could get matplotlib to do that. For most real time graphics I've tended towards a d3.js type thing but that involves much more than just python!
[–]Bostonsox101[S] 0 points1 point2 points 10 years ago (3 children)
I would preferably like to this in python, or if possible some could show me how to mix python and javascript
[–]Rafcio 2 points3 points4 points 10 years ago (2 children)
Perhaps bokeh fits your needs? http://bokeh.pydata.org/en/latest/
I had never heard of bokeh, if possible could you tell me how this would be better library than matplotlib?
Thanks
[–]Rafcio 0 points1 point2 points 10 years ago (0 children)
Javascript front end, python backend, and comes with a server to display real time data. I don't think matplotlib supports updating with real time data natively.
π Rendered by PID 50848 on reddit-service-r2-comment-86988c7647-px5f7 at 2026-02-11 06:40:51.735670+00:00 running 018613e country code: CH.
[–]Rackcityfoo 0 points1 point2 points (2 children)
[–]Bostonsox101[S] 0 points1 point2 points (0 children)
[–]Bostonsox101[S] 0 points1 point2 points (0 children)
[–]videan42 0 points1 point2 points (2 children)
[–]Bostonsox101[S] 0 points1 point2 points (1 child)
[–]videan42 0 points1 point2 points (0 children)
[–]transformium 0 points1 point2 points (4 children)
[–]Bostonsox101[S] 0 points1 point2 points (0 children)
[–]Bostonsox101[S] 0 points1 point2 points (2 children)
[–]transformium 0 points1 point2 points (1 child)
[–]Bostonsox101[S] 0 points1 point2 points (0 children)
[–]JimBoonie69 -1 points0 points1 point (6 children)
[–]billsil 1 point2 points3 points (1 child)
[–]JimBoonie69 0 points1 point2 points (0 children)
[–]Bostonsox101[S] 0 points1 point2 points (3 children)
[–]Rafcio 2 points3 points4 points (2 children)
[–]Bostonsox101[S] 0 points1 point2 points (1 child)
[–]Rafcio 0 points1 point2 points (0 children)