GnuplotEx.Plot.Palette (gnuplot_ex v0.2.0)

Named color palettes for surface plots and heatmaps.

Built-in Palettes

  • :viridis - Perceptually uniform, colorblind-friendly (default)
  • :magma - Dark to light, warm tones
  • :plasma - Blue to yellow through pink
  • :inferno - Dark to light, fire-like
  • :cividis - Colorblind-optimized blue-yellow
  • :turbo - Rainbow-like, high contrast

Example

GnuplotEx.surface(data) |> GnuplotEx.palette(:viridis)

Summary

Functions

Create a custom palette from a list of colors.

Get a named palette struct.

List all available named palettes.

Create a reversed version of a palette.

Convert a palette to gnuplot commands.

Check if a palette name is valid.

Types

t()

@type t() :: %GnuplotEx.Plot.Palette{
  colors: [String.t()] | nil,
  name: atom() | nil,
  reversed: boolean()
}

Functions

custom(colors)

@spec custom([String.t()]) :: t()

Create a custom palette from a list of colors.

Example

Palette.custom(["#440154", "#21918c", "#fde725"])

get(name)

@spec get(atom()) :: t()

Get a named palette struct.

Example

Palette.get(:viridis)

named_palettes()

@spec named_palettes() :: [atom()]

List all available named palettes.

Example

Palette.named_palettes()
# => [:viridis, :magma, :plasma, :inferno, :cividis, :turbo]

reversed(palette)

@spec reversed(t()) :: t()

Create a reversed version of a palette.

Example

Palette.get(:viridis) |> Palette.reversed()

to_commands(name)

@spec to_commands(t() | atom() | [String.t()] | nil) :: [list()]

Convert a palette to gnuplot commands.

Accepts:

  • nil - returns empty list
  • atom - looks up named palette
  • list - creates custom palette
  • %Palette{} - uses directly

Example

Palette.to_commands(:viridis)
# => [[:set, :palette, :viridis]]

Palette.to_commands(["#000", "#fff"])
# => [[:set, :palette, :defined, ~c"(0.0 \"#000\", 1.0 \"#fff\")"]]

valid_name?(name)

@spec valid_name?(atom()) :: boolean()

Check if a palette name is valid.