Plot live data that updates in real time using matplotlib backend
Project description
live_plotter
Plot live data that updates in real time using matplotlib backend
Installing
Install:
pip install live_plotter
Usage
In this library, we have two axes of variation. The first axis of variation is using either LivePlotter
or FastLivePlotter
. LivePlotter
is more flexible and dynamic, but this results in slower updates. FastLivePlotter
requires that the user specify the figure's shape from the beginning, but this allows it to update faster by modifying an existing plot rather than creating a new plot from scratch. Please refer to the associated example code for more details. The second axis of variation is using either LivePlotter
or LivePlotterGrid
. LivePlotter
creates 1 plot, while LivePlotterGrid
creates a grid of plots.
Lastly, you can add save_to_file_on_close=True
to save the figure to a file when the live plotter is deleted (either out of scope or end of script). You can add save_to_file_on_exception=True
to save the figure to a file when an exception occurs. Note this feature is experimental.
Options:
-
LivePlotter
-
LivePlotterGrid
-
FastLivePlotter
-
FastLivePlotterGrid
Live Plotter
python live_plotter.py
Fast Live Plotter
python fast_live_plotter.py
Example Usage of LivePlotter
import numpy as np
from live_plotter import LivePlotter
live_plotter = LivePlotter(default_title="sin")
x_data = []
for i in range(25):
x_data.append(2 * i)
live_plotter.plot(x_data=np.array(x_data), y_data=np.sin(x_data))
Example Usage of FastLivePlotter
import numpy as np
from live_plotter import FastLivePlotter
live_plotter = FastLivePlotter(title="sin")
x_data = []
for i in range(25):
x_data.append(2 * i)
live_plotter.plot(x_data=np.array(x_data), y_data=np.sin(x_data))
Example Usage of LivePlotterGrid
import numpy as np
from live_plotter import LivePlotterGrid
live_plotter_grid = LivePlotterGrid(default_title="sin")
x_data = []
for i in range(25):
x_data.append(i)
live_plotter_grid.plot_grid(
y_data_list=[np.sin(x_data), np.cos(x_data)],
title=["sin", "cos"],
)
Example Usage of FastLivePlotterGrid
import numpy as np
from live_plotter import FastLivePlotterGrid
live_plotter_grid = FastLivePlotterGrid(title="sin cos", n_rows=2, n_cols=1)
x_data = []
for i in range(25):
x_data.append(i)
live_plotter_grid.plot_grid(
y_data_list=[np.sin(x_data), np.cos(x_data)],
)
Example Usage of FastLivePlotterGrid
(recommended method for more complex examples)
import numpy as np
from live_plotter import FastLivePlotterGrid
NUM_DATAS = 7
plot_names = [f"exp(-{plot_idx}/10 * x)" for plot_idx in range(NUM_DATAS)]
live_plotter_grid = FastLivePlotterGrid.from_desired_n_plots(
title=plot_names, desired_n_plots=len(plot_names)
)
y_data_dict = defaultdict(list)
for i in range(25):
for plot_idx in range(NUM_DATAS):
y_data_dict[f"exp(-{plot_idx}/10 * x)"].append(np.exp(-plot_idx / 10 * i))
live_plotter_grid.plot_grid(
y_data_list=[np.array(y_data_dict[plot_name]) for plot_name in plot_names],
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for live_plotter-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40f0b0c9fa4f78b4b0c29370a5e8cf67ec68f234250a92afd16ce9c8d39642ee |
|
MD5 | 1e47a1ef5c6d9eac458d7cbf2f46a874 |
|
BLAKE2b-256 | 3336861a7163f20365faa5a124dd30b5c3fb0673ae2ffe8048518611a98e9b23 |