Skip to main content

logo

License: MIT Documentation Status build tests

bootplot is a package for black-box uncertainty visualization. By providing a dataset and a plotting function, bootplot automatically generates a static image and an animation of your uncertainty.

The method works by resampling the original dataset using bootstrap and plotting each bootstrapped sample. The plots are then combined into a single image or an animation. bootplot is also especially useful when dealing with small datasets, since it relies on the bootstrap method which robustly estimates uncertainty using resampling.

bootplot supports datasets represented as numpy arrays or pandas dataframes. Supported image output formats include popular formats such as JPG, PNG, BMP. Supported animation formats include popular formats such as GIF and MP4.

Installation

bootplot requires Python version 3.8 or greater. You can install it using:

pip install bootplot

Alternatively, you can install bootplot using:

git clone https://github.com/davidnabergoj/bootplot
cd bootplot
python setup.py install

Example

Suppose we have some data and their corresponding targets. We can model our targets with a regression line and visualize the uncertainty with the following code:

import numpy as np
from sklearn.linear_model import LinearRegression

from bootplot import bootplot


def plot_regression(data_subset, data_full, ax):
    # Plot full dataset
    ax.scatter(data_full[:, 0], data_full[:, 1])

    # Plot regression line trained on the subset
    lr = LinearRegression()
    lr.fit(data_subset[:, 0].reshape(-1, 1), data_subset[:, 1])
    ax.plot([-10, 10], lr.predict([[-10], [10]]), c='r')
    
    # Show root mean squared error in a text box
    rmse = np.sqrt(np.mean(np.square(data_subset[:, 1] - lr.predict(data_subset[:, 0].reshape(-1, 1)))))
    bbox_kwargs = dict(facecolor='none', edgecolor='black', pad=10.0)
    ax.text(x=0, y=-8, s=f'RMSE: {rmse:.4f}', fontsize=12, ha='center', bbox=bbox_kwargs)

    ax.set_xlim(-10, 10)
    ax.set_ylim(-10, 10)

if __name__ == '__main__':
    np.random.seed(0)

    # Dataset to be modeled
    dataset = np.random.randn(100, 2)
    noise = np.random.randn(len(dataset)) * 2.5
    dataset[:, 1] = dataset[:, 0] * 1.5 + 2 + noise

    # Create image and animation that show uncertainty
    bootplot(
        plot_regression,
        dataset,
        output_image_path='demo_image.png',
        output_animation_path='demo_animation.gif',
        verbose=True
    )

This will generate a static image and an animation, as shown below. The static image on points shows the full scattered dataset in blue and regression lines that correspond to each bootstrapped sample of the dataset in red. The spread of regression lines represents uncertainty according to the bootstrap process. We can also see the uncertainty in root mean squared error (RMSE). We see that only the first digit of RMSE is significant, since the decimal part is blurred. The animation on the right displays uncertainty by iterating over a sequence of plots containing regression lines.

See the examples folder for more examples, including bar charts, point plots, polynomial regression models, pie charts, text plots and pandas dataframes.

Documentation

Read the documentation and check out tutorials at https://bootplot.readthedocs.io/en/latest/

Metadata

Release files for bootplot 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bootplot 0.0.18
File Size Uploaded
bootplot-0.0.18.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bootplot 0.0.18
File Interpreter ABI Platform
bootplot-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 29.8 kB

Release files / bootplot-0.0.18.tar.gz

Download URL bootplot-0.0.18.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2c2293b6cb2ecb3fe322e4ac3a4c6db3e5f92c2fe180d08336ec6d5733651ecd
BLAKE2b-256 checksum
How to use checksums
a5be0d045042a84ec7797665c9ca2aede5155f8ca0cb1a296895f6011d1e3682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / bootplot-0.0.18-py3-none-any.whl

Download URL bootplot-0.0.18-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d177df1933d91633fd4daa19c3a0ee1a7f59f9d2449ee24919cb63b455418164
BLAKE2b-256 checksum
How to use checksums
d13d18220492f8ee015c66d6c7450ca290d94b3a7ace775bc3ceee27626d2bdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.0.18 This release

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page