theme

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package theme provides visual styling configurations for plots. Themes control non-data visual elements: background colors, fonts, grid lines, tick marks, spacing, and the discrete color palette used when no explicit color scale is set.

The preset catalog mirrors matplotlib's stylelib (https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html) and the curated set from raybuhr/pyplot-themes (https://github.com/raybuhr/pyplot-themes), with values lifted directly from the upstream .mplstyle files where they overlap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegister

func MustRegister(name Name, f Factory)

MustRegister is Register but panics on error. Intended for init().

func Register

func Register(name Name, f Factory) error

Register adds a named theme factory to the global registry. Returns an error if name is already taken; use MustRegister for init-time registration where a duplicate is a programmer error.

Intended both for built-in presets (registered via init() in their own files) and for user code that wants to add custom themes resolvable by name.

Types

type Factory

type Factory func() Theme

Factory builds a Theme on demand. Each preset is registered as a Factory so Resolve can return a fresh value per call (callers mutate the result via the Plot builder).

type FontConfig

type FontConfig struct {
	Family string
	Size   float64
	Color  color.Color
	Bold   bool
	Italic bool
}

FontConfig encapsulates text rendering parameters.

type GeomDefaults

type GeomDefaults struct {
	// PatchEdgeColor is the stroke color drawn around filled geoms.
	// Mirrors matplotlib's patch.edgecolor.
	// A nil value means "darken the fill color" (legacy behaviour).
	PatchEdgeColor color.Color
	// PatchEdgeWidth is the stroke line width for filled geoms (pixels).
	PatchEdgeWidth float64
	// PatchAlpha is the default fill opacity for filled geoms [0,1].
	// Zero is treated as "use geom's built-in default" (typically 0.85).
	PatchAlpha float64
}

GeomDefaults holds theme-level visual defaults for geometry primitives (bars, histograms, areas, boxplots). These act as fallbacks when the user has not explicitly overridden a property with a geom option.

type GridStyle

type GridStyle struct {
	MajorColor     color.Color
	MajorWidth     float64
	MinorColor     color.Color
	MinorWidth     float64
	MajorLineCount int       // 0 = auto
	DashPattern    []float64 // nil = solid, e.g. {4,4} = dashed, {2,3} = dotted
}

GridStyle controls major and minor grid lines.

type Name

type Name string

Name identifies a built-in theme.

const (
	Default Name = "default"

	// Library originals (kept for callers that selected them by name).
	Minimal Name = "minimal"
	Dark    Name = "dark"
	BW      Name = "bw"

	// Matplotlib stylelib presets.
	Ggplot              Name = "ggplot"
	Classic             Name = "classic"
	Grayscale           Name = "grayscale"
	Bmh                 Name = "bmh"
	Fivethirtyeight     Name = "fivethirtyeight"
	DarkBackground      Name = "dark_background"
	SolarizeLight2      Name = "solarize_light2"
	SolarizeDark        Name = "solarize_dark"
	TableauColorblind10 Name = "tableau_colorblind10"
	Fast                Name = "fast"

	// Seaborn family — chrome variants.
	Seaborn          Name = "seaborn"
	SeabornDarkgrid  Name = "seaborn_darkgrid"
	SeabornWhitegrid Name = "seaborn_whitegrid"
	SeabornDark      Name = "seaborn_dark"
	SeabornWhite     Name = "seaborn_white"
	SeabornTicks     Name = "seaborn_ticks"

	// Seaborn family — palette variants.
	SeabornDeep        Name = "seaborn_deep"
	SeabornMuted       Name = "seaborn_muted"
	SeabornBright      Name = "seaborn_bright"
	SeabornColorblind  Name = "seaborn_colorblind"
	SeabornPastel      Name = "seaborn_pastel"
	SeabornDarkPalette Name = "seaborn_dark_palette"

	// Seaborn family — font-size variants.
	SeabornPaper    Name = "seaborn_paper"
	SeabornNotebook Name = "seaborn_notebook"
	SeabornTalk     Name = "seaborn_talk"
	SeabornPoster   Name = "seaborn_poster"

	// Additions from raybuhr/pyplot-themes that don't overlap with matplotlib.
	PaulTol    Name = "paul_tol"
	Few        Name = "few"
	FewLight   Name = "few_light"
	FewDark    Name = "few_dark"
	UCBerkeley Name = "uc_berkeley"
	Tableau    Name = "tableau"

	// Colorblind-safe theme (Wong 2011, 8 colors).
	Colorblind Name = "colorblind"

	// Seasonal / contextual palettes on tableau chrome.
	Autumn1 Name = "autumn1"
	Autumn2 Name = "autumn2"
	Canyon  Name = "canyon"
	Chili   Name = "chili"
	Tomato  Name = "tomato"

	// Solarized light companion (pyplot-themes Solarized.light palette).
	SolarizeLight Name = "solarize_light"

	// Petroff10 (new in matplotlib 3.10).
	Petroff10 Name = "petroff10"
)

Built-in theme names.

Default resolves to the matplotlib ggplot preset; users who want the old hand-tuned light theme should pick a specific named preset instead.

func AllNames

func AllNames() []Name

AllNames returns every registered Name in alphabetical order.

type PanelStyle

type PanelStyle struct {
	Background  color.Color
	Border      color.Color
	BorderWidth float64
}

PanelStyle controls the data panel appearance.

type Spacing

type Spacing struct {
	MarginTop    float64
	MarginRight  float64
	MarginBottom float64
	MarginLeft   float64
	PanelSpacing float64
}

Spacing controls margins and inter-element spacing.

type TextStyles

type TextStyles struct {
	Title      FontConfig
	Subtitle   FontConfig
	AxisTitle  FontConfig
	TickLabel  FontConfig
	Legend     FontConfig
	Annotation FontConfig
}

TextStyles holds font configurations for different text roles.

type Theme

type Theme struct {
	Name       string
	Background color.Color
	Panel      PanelStyle
	Grid       GridStyle
	Text       TextStyles
	Ticks      TickStyle
	Spacing    Spacing
	// Palette is the discrete color cycle used when the plot has no
	// explicit color scale set. Mirrors matplotlib's axes.prop_cycle.
	// May be nil; callers fall back to colormap.Tab10.
	Palette []color.Color
	// Geom holds default visual properties for geometry primitives.
	// Individual geom options (WithColor, WithFill, etc.) always take precedence.
	Geom GeomDefaults
}

Theme encapsulates the complete visual styling for a plot.

func Resolve

func Resolve(name Name) (Theme, error)

Resolve returns a Theme for the given name. Empty name resolves to the default (the matplotlib ggplot preset). Unknown names return an error.

type TickStyle

type TickStyle struct {
	Length float64
	Width  float64
	Color  color.Color
}

TickStyle controls axis tick mark appearance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL