Statistical data visualization library for Python built on matplotlib
—
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.
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
"""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
"""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
"""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
"""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
"""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()# 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()# 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()# 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()# 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()# 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 objectInstall with Tessl CLI
npx tessl i tessl/pypi-seaborn