GitHub
deepbox/plot

Figure API & Core Charts

Figure, Axes, state helpers, rendering utilities, themes, palettes, and core 2D or 3D plotting primitives.
Rendering
type Color
export type Color = string;
Color specification as a CSS color string (e.g., "#ff0000", "rgb(255,0,0)").
type LegendOptions
export type LegendOptions = { /** Whether the legend should be visible */ readonly visible?: boolean; /** Legend placement */ readonly location?: "upper-right" | "upper-left" | "lower-right" | "lower-left"; /** Legend f…
Legend display options.
type PlotOptions
export type PlotOptions = { /** Optional label used by legends */ readonly label?: string; /** Line or marker color */ readonly color?: Color; /** Line width in pixels */ readonly linewidth?: number; /** Marker size in…
Options for customizing plot appearance and behavior.
type RenderedPDF
export type RenderedPDF = { /** Discriminator for the rendered output type */ readonly kind: "pdf"; /** PDF file data as byte array */ readonly bytes: Uint8Array; /** Page width in points */ readonly width: number; /**…
Result of PDF rendering containing the PDF file data.
type RenderedPNG
export type RenderedPNG = { /** Discriminator for the rendered output type */ readonly kind: "png"; /** Image width in pixels */ readonly width: number; /** Image height in pixels */ readonly height: number; /** PNG fil…
Result of PNG rendering containing the image dimensions and raw byte data.
type RenderedSVG
export type RenderedSVG = { /** Discriminator for the rendered output type */ readonly kind: "svg"; /** Complete SVG document as XML string */ readonly svg: string; };
Result of SVG rendering containing the complete SVG document as a string.

Axes

An Axes represents a single plot area within a Figure.

Figure

A Figure represents the entire plotting canvas.

show
export declare function show(options?: { readonly figure?: Figure; readonly format?: "svg" | "png"; }): RenderedSVG | Promise<RenderedPNG>;

Render a figure to SVG or PNG.

saveFig
export declare function saveFig(path: string, options?: { readonly figure?: Figure; readonly format?: "svg" | "png" | "pdf"; }): Promise<void>;

Save a figure to disk as SVG, PNG, or PDF.

plot
export declare function plot(x: Tensor, y: Tensor, options?: PlotOptions): void;

Plot a connected line series on the current axes.

scatter
export declare function scatter(x: Tensor, y: Tensor, options?: PlotOptions): void;

Plot unconnected points on the current axes.

bar
export declare function bar(x: Tensor, height: Tensor, options?: PlotOptions): void;

Plot vertical bars on the current axes.

barh
export declare function barh(y: Tensor, width: Tensor, options?: PlotOptions): void;

Plot horizontal bars on the current axes.

axhline
export declare function axhline(y: number, options?: { color?: string; linewidth?: number; label?: string; }): void;

Draw a horizontal line across the current axes at the given y value.

axvline
export declare function axvline(x: number, options?: { color?: string; linewidth?: number; label?: string; }): void;

Draw a vertical line across the current axes at the given x value.

stackedBar
export declare function stackedBar(x: Tensor, heights: readonly Tensor[], options?: { colors?: readonly string[]; labels?: readonly string[]; }): void;

Plot stacked vertical bars for multiple series on the current axes.

groupedBar
export declare function groupedBar(x: Tensor, heights: readonly Tensor[], options?: { colors?: readonly string[]; labels?: readonly string[]; }): void;

Plot grouped (side-by-side) vertical bars for multiple series on the current axes.

hist
export declare function hist(x: Tensor, bins?: number | (PlotOptions & { bins?: number; }), options?: PlotOptions): void;

Plot a histogram on the current axes.

boxplot
export declare function boxplot(data: Tensor, options?: PlotOptions): void;

Plot a box-and-whisker summary on the current axes.

violinplot
export declare function violinplot(data: Tensor, options?: PlotOptions): void;

Plot a violin summary on the current axes.

pie
export declare function pie(values: Tensor, labels?: readonly string[], options?: PlotOptions): void;

Plot a pie chart on the current axes.

legend
export declare function legend(options?: LegendOptions): void;

Show or configure a legend on the current axes.

heatmap
export declare function heatmap(data: Tensor, options?: PlotOptions): void;

Plot a heatmap for a 2D tensor.

imshow
export declare function imshow(data: Tensor, options?: PlotOptions): void;

Display a matrix as an image (alias of heatmap).

contour
export declare function contour(X: Tensor, Y: Tensor, Z: Tensor, options?: PlotOptions): void;

Plot contour lines for a 2D grid.

contourf
export declare function contourf(X: Tensor, Y: Tensor, Z: Tensor, options?: PlotOptions): void;

Plot filled contours for a 2D grid.

setTheme
export declare function setTheme(name: string): void;

Set the global plot theme.

getTheme
export declare function getTheme(): PlotTheme;

Get the current plot theme.

resetTheme
export declare function resetTheme(): void;

Reset the theme to default.

listThemes
export declare function listThemes(): readonly string[];

List available theme names.

surface
export declare function surface(xGrid: number[][], yGrid: number[][], zGrid: number[][], options?: import("./plots/Surface3D").Plot3DOptions): void;

Create a 3D surface plot.

wireframe
export declare function wireframe(xGrid: number[][], yGrid: number[][], zGrid: number[][], options?: import("./plots/Surface3D").Plot3DOptions): void;

Create a 3D wireframe plot.

scatter3d
export declare function scatter3d(x: number[], y: number[], z: number[], options?: import("./plots/Surface3D").Plot3DOptions): void;

Create a 3D scatter plot.

figure
export declare function figure(options?: { readonly width?: number; readonly height?: number; readonly background?: Color; }): Figure;

Create a new figure and set it as current.

gca
export declare function gca(): Axes;

Get the current axes, creating one if needed.

subplot
export declare function subplot(rows: number, cols: number, index: number, options?: { readonly padding?: number; readonly facecolor?: Color; }): Axes;

Create a subplot and set it as current axes.

getPalette
export declare function getPalette(name: string): readonly string[];

Get a named color palette.

getPaletteColor
export declare function getPaletteColor(name: string, index: number): string;

Get a color from a named palette by index (wraps around).

listPalettes
export declare function listPalettes(): string[];

List all available palette names.

plot-basic.ts
import {  figure,  gca,  saveFig,  setTheme,  wireframe,} from "deepbox/plot";import { tensor } from "deepbox/ndarray";const fig = figure({ width: 800, height: 400 });const ax = gca();const x = tensor([1, 2, 3, 4]);const y = tensor([2, 3, 5, 4]);setTheme("paper");ax.plot(x, y, { color: "#0f766e", label: "trend" });ax.bar(x, tensor([1, 2, 2, 3]), { color: "rgba(148, 163, 184, 0.5)" });wireframe(  [    [-1, 1],    [-1, 1],  ],  [    [-1, -1],    [1, 1],  ],  [    [0, 1],    [1, 0],  ],  { color: "#334155" });ax.legend();await saveFig("example.svg", { figure: fig });