Skip to main content

A collection of utilities to make it easier to interact with scipy in a marimo notebook, e.g. manipulate distributions, visualize data, etc.

Project description

PyPI Lint and Typecheck Ruff Code style: black

Marimo SciPy Utils

Utility functions for creating interactive marimo components with scipy distributions.

This package provides functions for creating and configuring interactive UI elements in marimo notebooks, with a focus on parameter input and visualization using scipy probability distributions.

Installation

uv add marimo-scipy-utils

Functions

See example notebook here

abbrev_format(x: float, pos: int | None) -> str

Format numbers with k/M suffixes for thousands/millions.

Parameters:

  • x: The number to format
  • pos: The tick position (unused but required by matplotlib formatter interface)

Returns:

  • str: The formatted number string with k/M suffix if applicable

Example:

abbrev_format(1500, None)  # Returns "2k"
abbrev_format(2500000, None)  # Returns "3M"
abbrev_format(42.7, None)  # Returns "42.7"

display_sliders(name: str, sliders: mo.ui.dictionary | mo.ui.slider, invars: dict[str, dict], dist: str | Callable | None = None, descriptions: dict = {}) -> mo.Html

Display parameter sliders with optional distribution plot.

Parameters:

  • name: Name of the parameter group to display
  • sliders: Either a single slider or dictionary of sliders for distribution params
  • invars: Dictionary to store input variable configurations
  • dist: Distribution to use (string name or callable), required for multi-sliders
  • descriptions: Optional dict mapping parameter names to descriptions

Returns:

  • Marimo component displaying the sliders and optional distribution plot

For a single slider, displays it as a constant parameter. For multiple sliders, displays them with a plot of the resulting distribution. Distribution must be specified for multiple sliders, either as a string name matching a scipy distribution or as a callable distribution object.

Raises:

  • DistributionConfigurationError: If dist is None for multiple sliders

generate_ranges(distribution: str, ranged_distkwargs: dict) -> dict

Generate parameter ranges for a probability distribution.

Takes a distribution name and dictionary of parameter ranges, validates the ranges against allowed bounds for that distribution, and returns a merged dictionary with complete range specifications.

Parameters:

  • distribution: Name of the probability distribution (e.g. "normal", "beta")
  • ranged_distkwargs: Dictionary mapping parameter names to their range specifications. Each range spec should have "lower" and "upper" bounds.

Returns:

  • dict: Complete parameter range specifications with distribution defaults merged with provided ranges

Raises:

  • MissingParameterError: If a required parameter range is not provided
  • ParameterBoundError: If a provided range exceeds the allowed bounds for a param

params_sliders(ranged_distkwargs: dict) -> mo.ui.dictionary

Create a dictionary of sliders for parameter ranges.

Takes a dictionary of param ranges and creates interactive sliders for each param. The sliders will be bounded by the lower/upper values specified in the ranges dict. The step size and initial value can optionally be specified per param.

Parameters:

  • ranged_distkwargs: Dictionary mapping parameter names to their range specifications. Each range spec should have "lower" and "upper" bounds, and optionally "step" and "value" keys.

Returns:

  • mo.ui.dictionary: A dictionary of marimo slider UI elements, one per parameter. Each slider will be configured according to the parameter's range spec.

Example:

ranges = {
    "mean": {"lower": 0, "upper": 100, "step": 1, "value": 50},
    "std": {"lower": 0, "upper": 10}
}
sliders = params_sliders(ranges)

Supported Distributions

Any scipy distribution can be used.

Included helpers following scipy distributions:

  • uniform: Uniform distribution
  • triang: Triangular distribution
  • beta: Beta distribution
  • norm: Normal distribution

Dependencies

  • marimo
  • matplotlib
  • scipy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marimo_scipy_utils-0.1.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marimo_scipy_utils-0.1.2-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file marimo_scipy_utils-0.1.2.tar.gz.

File metadata

  • Download URL: marimo_scipy_utils-0.1.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for marimo_scipy_utils-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b237b704deed866c58e859ff9449fa1fd87eb24fba2759dcfffec48d3b250408
MD5 4eb45fcaae628cc80811fcd19a7ad896
BLAKE2b-256 65793a229a94bbbcaaac89642f91d9b7af51af3740c5d4b47b913f793ba2afed

See more details on using hashes here.

Provenance

The following attestation bundles were made for marimo_scipy_utils-0.1.2.tar.gz:

Publisher: publish.yml on hbmartin/marimo-scipy-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file marimo_scipy_utils-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for marimo_scipy_utils-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cd33e7f137a1f95e5f3eafb1a5cbddcf5940baa35b2fd6a1b166e2e08ee5f80b
MD5 97dd1c31551d3004fe6695dd23c5ed07
BLAKE2b-256 6bdccac1b7784660cecd93427f3652590ed3479f286f23d18e7ea28626ea6f70

See more details on using hashes here.

Provenance

The following attestation bundles were made for marimo_scipy_utils-0.1.2-py3-none-any.whl:

Publisher: publish.yml on hbmartin/marimo-scipy-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page