VSUP: Value-Suppressing Uncertainty Palettes
A Python package for visualizing data with uncertainty using Value-Suppressing Uncertainty Palettes (VSUPs). Inspired by https://github.com/uwdata/vsup.
Installation
Development
The project is developed with uv.
To check for a local python environment, run:
Also install the pre-commit hooks with:
uv tool install pre-commit
pre-commit install
Usage
from vsup import VSUP
import numpy as np
import matplotlib.pyplot as plt
# Create a grid of values and uncertainties for better visualization
n_points = 50
step = 1 / n_points
values = np.linspace(step / 2, 1 - step / 2, n_points)
uncertainties = np.linspace(step / 2, 1 - step / 2, n_points)
# Create a 2D grid
values, uncertainties = np.meshgrid(values, uncertainties)
# Colorize the data
axs = plt.subplots(3, 3, figsize=(9, 9))[1]
for row, quantization in zip(axs, [None, "linear", "tree"]):
for ax, mode in zip(row, ["us", "ul", "usl"]):
vsup = VSUP(palette="flare", mode=mode, quantization=quantization)
colors = vsup(values, uncertainties)
ax.pcolormesh(values, uncertainties, colors)
# ax.set_title(f"{mode}") #\n({description})")
ax.set_xlabel("Value")
ax.set_ylabel("Uncertainty")
Example
import%20marimo%20as%20mo%0A%0Aimport%20micropip%0Aawait%20micropip.install(%5B%22vsup%22%2C%20%22matplotlib%22%2C%20%22numpy%22%5D)%0A%0Afrom%20matplotlib%20import%20colormaps%0A%0Aseaborn_colors%20%3D%20%5B%22flare%22%2C%20%22rocket%22%2C%20%22crest%22%2C%20%22mako%22%2C%20%22coolwarm%22%2C%20%22vlag%22%2C%20%22icefire%22%2C%20%22ch%3As%3D-.2%2Cr%3D.6%22%2C%20%22ch%3Astart%3D.2%2Crot%3D-.3%22%2C%20%22husl%22%5D%0Amatplotlib_colors%20%3D%20list(colormaps)%0Acolors%20%3D%20seaborn_colors%20%2B%20matplotlib_colors%0A%0Apalette%20%3D%20mo.ui.dropdown(options%3Dcolors%2C%20value%3D%22flare%22%2C%20label%3D%22Palette%3A%22)%0Apalette
def%20palette_not_selected()%3A%0A%20%20%20%20return%20mo.md(%22Please%20select%20a%20palette%20first.%22)%0A%0Adef%20showcase_palette(palette%3A%20str)%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20from%20vsup%20import%20VSUP%0A%20%20%20%20%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20except%20ImportError%3A%0A%20%20%20%20%20%20%20%20return%20mo.md(%22Packages%20are%20still%20loading%2C%20please%20wait%20a%20moment.%22)%0A%0A%20%20%20%20%23%20Create%20a%20grid%20of%20values%20and%20uncertainties%20for%20better%20visualization%0A%20%20%20%20n_points%20%3D%2050%0A%20%20%20%20step%20%3D%201%2Fn_points%0A%20%20%20%20values%20%3D%20np.linspace(step%2F2%2C%201-step%2F2%2C%20n_points)%0A%20%20%20%20uncertainties%20%3D%20np.linspace(step%2F2%2C%201-step%2F2%2C%20n_points)%0A%0A%20%20%20%20%23%20Create%20a%202D%20grid%0A%20%20%20%20values%2C%20uncertainties%20%3D%20np.meshgrid(values%2C%20uncertainties)%0A%0A%20%20%20%20%23%20Colorize%20the%20data%0A%20%20%20%20size%20%3D%209%0A%20%20%20%20fig%2C%20axs%20%3D%20plt.subplots(3%2C%203%2C%20figsize%3D(size%2C%20size))%0A%0A%20%20%20%20for%20row%2C%20quantization%20in%20zip(axs%2C%20%5BNone%2C%20'linear'%2C'tree'%5D)%3A%0A%20%20%20%20%20%20%20%20for%20ax%2C%20mode%20in%20zip(row%2C%20%5B%22us%22%2C%20%22ul%22%2C%20%22usl%22%5D)%3A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20vsup%20%3D%20VSUP(palette%3Dpalette%2C%20mode%3Dmode%2C%20quantization%3Dquantization)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20colors%20%3D%20vsup(values%2C%20uncertainties)%0A%20%20%20%20%20%20%20%20%20%20%20%20ax.pcolormesh(values%2C%20uncertainties%2C%20colors)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20ax.set_title(f%22%7Bmode%7D%22)%20%20%23%5Cn(%7Bdescription%7D)%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20ax.set_xlabel(%22Value%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20ax.set_ylabel(%22Uncertainty%22)%0A%0A%20%20%20%20fig.suptitle(f%22VSUP%3A%20%7Bpalette%7D%20palette%22)%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20return%20fig%0A%0Afunc%20%3D%20palette_not_selected%20if%20not%20palette.value%20else%20lambda%20%3A%20showcase_palette(palette.value)%0Afunc()
Features
- Three visualization modes:
- USL: Uncertainty mapped to Saturation (chroma) and Lightness
- US: Uncertainty mapped to Saturation
- UL: Uncertainty mapped to Lightness
- Two quantization mods:
- Linear: independent binning of values and uncertainties
- Tree: value bins depend on uncertainty bin: lower uncertainty, higher value resolution
- Support for any matplotlib and seaborn colormaps
Citation
If you use this package in your research, please cite the original VSUP paper:
@inproceedings{2018-uncertainty-palettes,
title = {Value-Suppressing Uncertainty Palettes},
author = {Michael Correll AND Dominik Moritz AND Jeffrey Heer},
booktitle = {ACM Human Factors in Computing Systems (CHI)},
year = {2018},
url = {http://idl.cs.washington.edu/papers/uncertainty-palettes},
}
License
MIT License