CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-seaborn

Statistical data visualization library for Python built on matplotlib

Pending
Overview
Eval results
Files

styling-themes.mddocs/

Styling and Themes

Configure plot aesthetics, themes, color palettes, and plotting contexts with extensive customization options for publication-quality graphics. These functions provide comprehensive control over the visual appearance of seaborn and matplotlib plots.

Capabilities

Theme Configuration

Set overall aesthetic parameters and make seaborn the default matplotlib style.

def set_theme(
    context="notebook",
    style="darkgrid",
    palette="deep",
    font="sans-serif",
    font_scale=1,
    color_codes=True,
    rc=None
):
    """
    Set multiple theme parameters in one step.
    
    Parameters:
    - context: str, plotting context ("paper", "notebook", "talk", "poster")
    - style: str, axes style ("darkgrid", "whitegrid", "dark", "white", "ticks")
    - palette: str or list, color palette
    - font: str, font family
    - font_scale: float, scaling factor for font sizes
    - color_codes: bool, use seaborn color codes
    - rc: dict, matplotlib rcParams to override
    """

def set(
    context="notebook",
    style="darkgrid", 
    palette="deep",
    font="sans-serif",
    font_scale=1,
    color_codes=True,
    rc=None
):
    """
    Alias for set_theme() - sets aesthetic parameters in one step.
    """

Style Management

Control the appearance of plot axes and backgrounds.

def axes_style(style=None, rc=None):
    """
    Get the parameters that control the general style of the plots.
    
    Parameters:
    - style: str, style name ("darkgrid", "whitegrid", "dark", "white", "ticks")
    - rc: dict, parameter overrides
    
    Returns:
    dict of matplotlib rcParams
    
    Can be used as context manager:
    with sns.axes_style("white"):
        # plots with white background
    """

def set_style(style, rc=None):
    """
    Set the aesthetic style of the plots.
    
    Parameters:
    - style: str, style name or dict of parameters
    - rc: dict, parameter overrides
    """

Plotting Context

Control the scale of plot elements for different contexts.

def plotting_context(context=None, font_scale=1, rc=None):
    """
    Get the parameters that control the scaling of plot elements.
    
    Parameters:
    - context: str, context name ("paper", "notebook", "talk", "poster")
    - font_scale: float, scaling factor for font sizes
    - rc: dict, parameter overrides
    
    Returns:
    dict of matplotlib rcParams
    
    Can be used as context manager:
    with sns.plotting_context("poster"):
        # plots scaled for poster presentation
    """

def set_context(context, font_scale=1, rc=None):
    """
    Set the plotting context parameters.
    
    Parameters:
    - context: str, context name or dict of parameters
    - font_scale: float, scaling factor for font sizes
    - rc: dict, parameter overrides
    """

Palette Management

Set and retrieve color palettes for consistent color schemes.

def set_palette(palette, n_colors=None, desat=None, color_codes=False):
    """
    Set the matplotlib color cycle using a seaborn palette.
    
    Parameters:
    - palette: str, list, or dict, palette specification
    - n_colors: int, number of colors in cycle
    - desat: float, desaturation factor (0-1)
    - color_codes: bool, use seaborn color codes
    """

def color_palette(palette=None, n_colors=None, desat=None, as_cmap=False):
    """
    Return a list of colors or continuous colormap defining a palette.
    
    Parameters:
    - palette: str, list, or None, palette specification
    - n_colors: int, number of colors to return
    - desat: float, desaturation factor (0-1)
    - as_cmap: bool, return matplotlib Colormap object
    
    Returns:
    list of RGB tuples or matplotlib Colormap
    """

Reset Functions

Restore default settings.

def reset_defaults():
    """Restore all seaborn style settings to default values."""

def reset_orig():
    """Restore all matplotlib rcParams to original settings before seaborn import."""

Color Code Configuration

Control interpretation of matplotlib color abbreviations.

def set_color_codes(palette="deep"):
    """
    Change how matplotlib color shorthands are interpreted.
    
    Parameters:
    - palette: str, palette name for color codes
    
    Calling this changes the meaning of abbreviations like 'b', 'g', 'r', etc.
    """

Available Styles

Axes Styles

  • "darkgrid": Dark background with white grid lines (default)
  • "whitegrid": White background with gray grid lines
  • "dark": Dark background without grid
  • "white": White background without grid
  • "ticks": White background with ticks but no grid

Plotting Contexts

  • "paper": Smallest scale, for journal figures
  • "notebook": Medium scale, for Jupyter notebooks (default)
  • "talk": Larger scale, for presentations
  • "poster": Largest scale, for posters

Usage Examples

Basic Theme Setup

import seaborn as sns
import matplotlib.pyplot as plt

# Set overall theme
sns.set_theme(style="whitegrid", palette="pastel")

# Create a plot - will use theme settings
tips = sns.load_dataset("tips")
sns.boxplot(data=tips, x="day", y="total_bill")
plt.show()

Style Context Manager

# Temporarily change style
with sns.axes_style("white"):
    sns.scatterplot(data=tips, x="total_bill", y="tip")
    plt.show()

# Back to default style
sns.boxplot(data=tips, x="day", y="total_bill")
plt.show()

Context Scaling

# Scale for poster presentation
sns.set_context("poster", font_scale=1.2)
sns.barplot(data=tips, x="day", y="total_bill")
plt.show()

# Reset to notebook context
sns.set_context("notebook")

Custom Palette

# Set custom color palette
custom_colors = ["#FF6B6B", "#4ECDC4", "#45B7D1", "#FFA07A"]
sns.set_palette(custom_colors)

# Plots will use custom colors
sns.countplot(data=tips, x="day")
plt.show()

Color Codes

# Enable seaborn color codes
sns.set_color_codes("muted")

# Now 'b', 'g', 'r' use seaborn colors
plt.plot([1, 2, 3], [1, 4, 2], 'b-')  # Uses seaborn blue
plt.show()

Context Manager for Scaling

# Temporarily scale for presentation
with sns.plotting_context("talk", font_scale=1.5):
    fig, axes = plt.subplots(2, 2, figsize=(12, 10))
    
    sns.scatterplot(data=tips, x="total_bill", y="tip", ax=axes[0,0])
    sns.boxplot(data=tips, x="day", y="total_bill", ax=axes[0,1])
    sns.histplot(data=tips, x="total_bill", ax=axes[1,0])
    sns.barplot(data=tips, x="day", y="total_bill", ax=axes[1,1])
    
    plt.tight_layout()
    plt.show()

Reset to Defaults

# Reset all seaborn settings
sns.reset_defaults()

# Or reset to pre-seaborn matplotlib settings
sns.reset_orig()

Fine-tuned Theme

# Detailed theme customization
sns.set_theme(
    context="notebook",
    style="ticks",
    palette="Set2",
    font="serif",
    font_scale=1.1,
    rc={
        "axes.spines.right": False,
        "axes.spines.top": False,
        "axes.linewidth": 1.2,
        "grid.alpha": 0.4
    }
)

sns.scatterplot(data=tips, x="total_bill", y="tip", hue="smoker")
plt.show()

Types

# Style options
AxesStyle = Literal["darkgrid", "whitegrid", "dark", "white", "ticks"]
PlottingContext = Literal["paper", "notebook", "talk", "poster"]

# Palette specifications
PaletteSpec = str | list | dict | None

# RC parameters
RCParams = dict[str, Any]  # matplotlib rcParams dictionary

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