https://github.com/ziofil/live_plot
A jupyter-lab function for updating a plot dynamically in-place.
https://github.com/ziofil/live_plot
dynamic-plots jupyter-notebook jupyterlab matplotlib plotting python
Last synced: 5 months ago
JSON representation
A jupyter-lab function for updating a plot dynamically in-place.
- Host: GitHub
- URL: https://github.com/ziofil/live_plot
- Owner: ziofil
- Created: 2018-10-06T11:07:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-06T11:37:48.000Z (over 7 years ago)
- Last Synced: 2025-10-12T09:32:08.342Z (5 months ago)
- Topics: dynamic-plots, jupyter-notebook, jupyterlab, matplotlib, plotting, python
- Language: Jupyter Notebook
- Size: 2.62 MB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# live_plot
A jupyter-lab function for updating a plot dynamically in-place.
### Disclaimer
Live plot covers only `pyplot.plot` (for now) and requires some explicit imports. It works with jupyter_lab on my mac, I haven't tested it in any other environemnt. You are welcome to create pull requests.
The working principle is simple: create a loop in which you populate a dictionary with the data you want to plot. Use the keys to label different datasets. Still within the loop, pass it to live_plot, sit back and watch.
### Example
After importing the required libraries and defining the `live_plot` function (see example notebook), populate the dictionary in a loop. Better still, use a `defaultdict` to return an empty list the first time you use a new key:
```python
import numpy as np
from collections import defaultdict
data = defaultdict(list)
for i in range(100):
data['foo'].append(np.sin(i/10) + 0.1*np.random.random())
data['bar'].append(np.random.random()+0.3)
live_plot(data)
```
you should observe this in the cell output (the framerate will depend on the speed of the loop)

Make sure you create a few cells below the animation, otherwise the view snaps back into place and it's a bit annoying.