plotstream is a Python package that allows you to stream plots to a web browser using Streamlit.
Project description
PlotStream
PlotStream allows you to register your Python functions with a simple decorator, @plotstream_function, and automatically create dynamic, interactive dashboards to visualize their outputs. It supports a variety of data formats like DataFrames, arrays, and lists, and generates customizable charts with minimal effort.
Features
- Simple Function Registration: Use
@plotstream_functionto register functions effortlessly. - Dynamic Dashboards: Automatically generate Streamlit dashboards with interactive controls for function inputs.
- Customizable Charts: Define chart types, axis mappings, colors, and more.
- Multi-format Support: Works seamlessly with Pandas DataFrames, Series, NumPy arrays, and Python lists.
- Minimal Code Overhead: Just decorate your functions and call
run_plotstream_app().
Usage
-
Register your functions with the
@plotstream_functiondecorator. Customize the parameters to control how the function is visualized.None of the parameters are required, but you can specify the following:
from plotstream import plotstream_function, run_plotstream_app
import pandas as pd
import numpy as np
@plotstream_function(
name="Sine Wave",
graph="Trigonometry Graph",
chart_type="Line",
color="#FF5733",
x_col="x",
y_col="y",
)
def sine_wave(a: float = 1.0, b: float = 2.0, n: int = 100) -> pd.DataFrame:
"""
Generate a sine wave with given parameters.
Args:
a (float): Amplitude of the sine wave.
b (float): Frequency of the sine wave.
n (int): Number of points.
Returns:
pd.DataFrame: A DataFrame containing the sine wave (x, y).
"""
x = np.linspace(0, 10, n)
y = a * np.sin(b * x)
return pd.DataFrame({"x": x, "y": y})
- Run the PlotStream app to generate the dashboard.
run_plotstream_app()
The Streamlit dashboard will open in your browser, allowing you to:
- Select from registered functions.
- Adjust inputs using dynamically generated controls.
- View and interact with the resulting visualizations.
How It Works
-
Function Registration:
Use @plotstream_function to register your function along with metadata like chart type, axis mappings, and colors. Metadata is stored in a global dictionary (FUNCTIONS) and serialized for reuse.
-
Data Processing:
The process_data utility handles different data formats (DataFrames, arrays, lists) and extracts x/y data for visualization.
-
Streamlit App:
The run_plotstream_app() function launches the Streamlit app, dynamically loading registered functions and their associated metadata.
Key Decorator Parameters
When using @plotstream_function, you can customize the visualization with the following parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
None |
The name of the function (appears in the dashboard). |
graph |
str |
"Default Graph" |
The graph this function belongs to (groups functions visually). |
chart_type |
str |
"Line" |
The chart type ("Line", "Scatter", etc.). |
secondary_y_axis |
bool |
False |
Whether to use a secondary Y-axis. |
secondary_graph |
bool |
False |
Whether to plot this series on a secondary graph. |
color |
str (hex) |
Auto-assigned |
The color of the series (default is auto-assigned). |
x_col |
`str | int | None` |
y_col |
`str | int | None` |
row_major |
bool |
True |
Whether arrays are row-major (True) or column-major (False). |
Future Improvements
- Add support for more chart types.
- Add support for more data formats (including multi graphs for multi columns DataFrames).
- Add support for more controls (e.g., sliders, dropdowns, etc.).
- Provide enhanced error handling and logging.
- Ignore unsupported input data types.
- Function naming in legend.
License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plotstream-0.2.6.tar.gz.
File metadata
- Download URL: plotstream-0.2.6.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6bf42cf29ddb69811384bc20f44b362a8bda42fe76cbb4078839e86426f8363
|
|
| MD5 |
daccf5c29c19a19aa317792c7f547ba3
|
|
| BLAKE2b-256 |
ae01e0271e4ae14d7aad7b0fe296a37df54cc728f754c3fa8f0e52c844e6792d
|
File details
Details for the file plotstream-0.2.6-py3-none-any.whl.
File metadata
- Download URL: plotstream-0.2.6-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3e0108ec50798b2cc82d51ef1c6ff47a579b6e4602fe6c987941bfc365ad0a2
|
|
| MD5 |
a0578968f7f80583f85392352fc34c65
|
|
| BLAKE2b-256 |
0ea51e33aef8653a6cfc86824093105106a4f0d0fd1afbbe9515e0d76b125fc4
|