CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-seaborn

Statistical data visualization library for Python built on matplotlib

Pending
Overview
Eval results
Files

interactive-widgets.mddocs/

Interactive Color Palette Widgets

Interactive Jupyter widgets for creating and customizing color palettes in real-time. These functions provide GUI controls for palette selection and customization, enabling experimentation and fine-tuning of color schemes within notebook environments.

Requirements: IPython 2+ and ipywidgets package. Must be used in Jupyter notebooks.

Capabilities

ColorBrewer Palette Selection

Interactive widget for selecting from predefined ColorBrewer palettes.

def choose_colorbrewer_palette(data_type, as_cmap=False):
    """
    Select a palette from the ColorBrewer set using interactive controls.
    
    Parameters:
    - data_type: str, type of data visualization
      * "sequential" - ordered data from low to high  
      * "diverging" - data with meaningful midpoint
      * "qualitative" - categorical data without order
    - as_cmap: bool, return matplotlib colormap if True, list of colors if False
    
    Returns:
    List of colors or matplotlib colormap
    """

Dark Sequential Palette Creation

Interactive widget for creating dark sequential palettes with custom color parameters.

def choose_dark_palette(input="husl", as_cmap=False):
    """
    Launch interactive widget to create dark sequential palette.
    
    Dark palettes transition from dark colors to a specified bright color,
    suitable for data ranging from uninteresting low to interesting high values.
    
    Parameters:
    - input: str, color space for seed value
      * "husl" - perceptually uniform color space (default)
      * "hls" - hue, lightness, saturation
      * "rgb" - red, green, blue
    - as_cmap: bool, return matplotlib colormap if True, list of colors if False
    
    Returns:
    List of colors or matplotlib colormap
    """

Light Sequential Palette Creation

Interactive widget for creating light sequential palettes with custom color parameters.

def choose_light_palette(input="husl", as_cmap=False):
    """
    Launch interactive widget to create light sequential palette.
    
    Light palettes transition from light colors to a specified dark color,
    suitable for data ranging from uninteresting low to interesting high values.
    
    Parameters:
    - input: str, color space for seed value  
      * "husl" - perceptually uniform color space (default)
      * "hls" - hue, lightness, saturation
      * "rgb" - red, green, blue
    - as_cmap: bool, return matplotlib colormap if True, list of colors if False
    
    Returns:
    List of colors or matplotlib colormap
    """

Diverging Palette Creation

Interactive widget for creating custom diverging palettes with adjustable endpoints and midpoint.

def choose_diverging_palette(as_cmap=False):
    """
    Launch interactive widget to create diverging color palette.
    
    Diverging palettes have two distinct colors at the extremes with a neutral
    midpoint, ideal for data with meaningful center values (e.g., change scores).
    
    Parameters:
    - as_cmap: bool, return matplotlib colormap if True, list of colors if False
    
    Widget Controls:
    - h_neg: negative endpoint hue (0-359)
    - h_pos: positive endpoint hue (0-359) 
    - s: saturation level (0-99)
    - l: lightness level (0-99)
    - sep: color separation (1-50)
    - n: number of colors (2-16)
    - center: midpoint style ("light" or "dark")
    
    Returns:
    List of colors or matplotlib colormap
    """

Cubehelix Palette Creation

Interactive widget for creating sequential cubehelix palettes with extensive parameter control.

def choose_cubehelix_palette(as_cmap=False):
    """
    Launch interactive widget to create sequential cubehelix palette.
    
    Cubehelix palettes provide sequential color progression with more hue variance,
    helping distinguish wider ranges of values while maintaining perceptual ordering.
    
    Parameters:
    - as_cmap: bool, return matplotlib colormap if True, list of colors if False
    
    Widget Controls:
    - n_colors: number of colors (2-16)
    - start: starting hue position (0-3)
    - rot: hue rotation, positive=clockwise (-1 to 1)
    - gamma: nonlinearity factor (0-5)
    - hue: saturation intensity (0-1)
    - light: lightest color intensity (0-1)
    - dark: darkest color intensity (0-1)
    - reverse: reverse color order (boolean)
    
    Returns:
    List of colors or matplotlib colormap
    """

Usage Examples

ColorBrewer Sequential Palette

import seaborn as sns

# Interactive sequential palette selection
pal = sns.choose_colorbrewer_palette("sequential")

# Use the selected palette
tips = sns.load_dataset("tips")
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="size", palette=pal)
plt.show()

Custom Dark Palette

# Interactive dark palette creation
dark_pal = sns.choose_dark_palette()

# Apply to heatmap
flights = sns.load_dataset("flights")
flights_pivot = flights.pivot("month", "year", "passengers")
sns.heatmap(flights_pivot, cmap=dark_pal, cbar_kws={"shrink": 0.8})
plt.show()

Diverging Palette for Change Data

# Interactive diverging palette for change scores
div_pal = sns.choose_diverging_palette(as_cmap=True)

# Create sample change data
import numpy as np
np.random.seed(42)
change_data = np.random.randn(10, 10)

# Use diverging colormap
sns.heatmap(change_data, cmap=div_pal, center=0, 
           square=True, cbar_kws={"shrink": 0.8})
plt.title("Change Scores from Baseline")
plt.show()

Cubehelix for Scientific Data

# Interactive cubehelix palette
cube_pal = sns.choose_cubehelix_palette(as_cmap=True)

# Apply to scientific visualization
brain = sns.load_dataset("brain_networks")
sns.heatmap(brain.corr(), cmap=cube_pal, square=True)
plt.title("Brain Network Correlations")
plt.show()

ColorBrewer Qualitative Palette

# Interactive qualitative palette selection
qual_pal = sns.choose_colorbrewer_palette("qualitative")

# Use for categorical data
tips = sns.load_dataset("tips")
sns.boxplot(data=tips, x="day", y="total_bill", palette=qual_pal)
plt.show()

Interactive Controls Description

ColorBrewer Widget Controls

  • Palette Name: Dropdown of available ColorBrewer palettes
  • Colors (n): Number of colors to include (2-18 for sequential/diverging, 2-16 for qualitative)
  • Desaturation: Reduce color saturation (0-1 slider)
  • Variant: Regular, reverse, or dark versions

Dark/Light Palette Controls

  • Color Space Selection: Choose between RGB, HLS, or HUSL color spaces
  • Color Components: Sliders for R/G/B, H/L/S, or H/S/L values depending on color space
  • Number of Colors: Adjust palette size (3-17 colors)

Diverging Palette Controls

  • Negative Hue: Hue for negative values (0-359 degrees)
  • Positive Hue: Hue for positive values (0-359 degrees)
  • Saturation/Lightness: Overall color intensity and brightness
  • Separation: Distance between endpoint colors
  • Center Style: Light or dark midpoint

Cubehelix Controls

  • Start Position: Initial hue position in color space
  • Rotation: Direction and amount of hue rotation
  • Gamma: Nonlinear intensity scaling
  • Saturation: Color vividness
  • Light/Dark Endpoints: Brightness range limits
  • Reverse: Flip color order

Types

# Color space options
ColorSpace = Literal["rgb", "hls", "husl"]

# Data type categories  
DataType = Literal["sequential", "diverging", "qualitative"]

# Center options for diverging palettes
CenterType = Literal["light", "dark"]

# Return types
ColorList = list[tuple[float, float, float]]  # List of RGB tuples
ColorMap = matplotlib.colors.Colormap  # Matplotlib colormap object

Install with Tessl CLI

npx tessl i tessl/pypi-seaborn

docs

categorical-plots.md

color-palettes.md

distribution-plots.md

grid-plots.md

index.md

interactive-widgets.md

matrix-plots.md

objects-interface.md

relational-plots.md

styling-themes.md

utilities.md

tile.json