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.0.tar.gz (10.6 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.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: marimo_scipy_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 10.6 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.0.tar.gz
Algorithm Hash digest
SHA256 ee57bfaf6a10199f7fc3100fe0565b59a4dabf6641c74bc516172ee82b737b43
MD5 8b5580e271672d40432dee4f691aa89b
BLAKE2b-256 654ef80d46fd7317784677b2b286205d35e32c04864fd9f5bf856a94d5deb48b

See more details on using hashes here.

Provenance

The following attestation bundles were made for marimo_scipy_utils-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for marimo_scipy_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49c1f46e2150eb29c220f1529db72dbd6116b85a2245053702dca414bc0a9666
MD5 fbabd4adb1fd5c7c72cf23bf2a60118a
BLAKE2b-256 935c9fb4aba81156dc95dce5b78b496b086f841d951bc6644950662f520eea17

See more details on using hashes here.

Provenance

The following attestation bundles were made for marimo_scipy_utils-0.1.0-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