Utils API#
altair2svg#
Convert an Altair chart to SVG format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chart
|
An Altair chart object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The SVG representation of the chart as a string. |
Note
This function writes to disk temporarily as Altair doesn't provide an in-memory API for SVG conversion.
Source code in wigglystuff/utils.py
refresh_matplotlib#
Decorator to convert matplotlib plotting functions to base64-encoded images.
This decorator wraps a matplotlib plotting function and returns a base64-encoded data URI that can be used with ImageRefreshWidget for live updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
A function that creates matplotlib plots using plt commands. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A wrapper function that returns a base64-encoded JPEG data URI. |
Example
@refresh_matplotlib ... def plot_sine(x): ... plt.plot(x, np.sin(x)) ... widget = ImageRefreshWidget() widget.src = plot_sine(np.linspace(0, 2*np.pi, 100))
Source code in wigglystuff/utils.py
refresh_altair#
Decorator to convert Altair chart functions to SVG strings.
This decorator wraps a function that returns an Altair chart and converts the chart to an SVG string that can be used with HTMLRefreshWidget for live updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
A function that returns an Altair chart object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A wrapper function that returns an SVG string representation of the chart. |
Example
@refresh_altair ... def create_chart(data): ... return alt.Chart(data).mark_bar().encode(x='x', y='y') ... widget = HTMLRefreshWidget() widget.html = create_chart(df)