Skip to main content

Overview

Basic plotting functions provide fundamental chart types for visualizing data.

Functions

plot

Plot a connected line series on the current axes.
function plot(x: Tensor, y: Tensor, options?: PlotOptions): void
x
Tensor
required
X-axis values
y
Tensor
required
Y-axis values
options
PlotOptions
Plot styling options (color, linewidth, label, etc.)
Example:
import { plot, tensor } from 'deepbox/plot';

const x = tensor([0, 1, 2, 3, 4]);
const y = tensor([0, 1, 4, 9, 16]);
plot(x, y, { color: '#1f77b4', linewidth: 2 });

scatter

Plot unconnected points on the current axes.
function scatter(x: Tensor, y: Tensor, options?: PlotOptions): void
x
Tensor
required
X-axis values
y
Tensor
required
Y-axis values
options
PlotOptions
Plot styling options (color, size, label, etc.)
Example:
import { scatter, tensor } from 'deepbox/plot';

const x = tensor([0, 1, 2, 3, 4]);
const y = tensor([0, 1, 4, 9, 16]);
scatter(x, y, { color: '#ff7f0e', size: 5 });

bar

Plot vertical bars on the current axes.
function bar(x: Tensor, height: Tensor, options?: PlotOptions): void
x
Tensor
required
X-axis positions
height
Tensor
required
Bar heights
options
PlotOptions
Plot styling options

barh

Plot horizontal bars on the current axes.
function barh(y: Tensor, width: Tensor, options?: PlotOptions): void
y
Tensor
required
Y-axis positions
width
Tensor
required
Bar widths
options
PlotOptions
Plot styling options

hist

Plot a histogram on the current axes.
function hist(
  x: Tensor,
  bins?: number | (PlotOptions & { bins?: number }),
  options?: PlotOptions
): void
x
Tensor
required
Data values
bins
number | object
Number of bins (default: 10) or options object
options
PlotOptions
Plot styling options
Example:
import { hist, randn } from 'deepbox/plot';

const data = randn([1000]);
hist(data, 30, { color: '#2ca02c' });

heatmap

Plot a heatmap for a 2D tensor.
function heatmap(data: Tensor, options?: PlotOptions): void
data
Tensor
required
2D tensor data
options
PlotOptions
Plot styling options (colormap, vmin, vmax, etc.)
Example:
import { heatmap, tensor } from 'deepbox/plot';

const data = tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
heatmap(data, { colormap: 'viridis' });

imshow

Display a matrix as an image (alias of heatmap).
function imshow(data: Tensor, options?: PlotOptions): void
data
Tensor
required
2D tensor data
options
PlotOptions
Plot styling options

contour

Plot contour lines for a 2D grid.
function contour(X: Tensor, Y: Tensor, Z: Tensor, options?: PlotOptions): void
X
Tensor
required
X-coordinate grid
Y
Tensor
required
Y-coordinate grid
Z
Tensor
required
Z values at grid points
options
PlotOptions
Plot styling options

contourf

Plot filled contours for a 2D grid.
function contourf(X: Tensor, Y: Tensor, Z: Tensor, options?: PlotOptions): void
X
Tensor
required
X-coordinate grid
Y
Tensor
required
Y-coordinate grid
Z
Tensor
required
Z values at grid points
options
PlotOptions
Plot styling options

boxplot

Plot a box-and-whisker summary on the current axes.
function boxplot(data: Tensor, options?: PlotOptions): void
data
Tensor
required
Data values
options
PlotOptions
Plot styling options

violinplot

Plot a violin summary on the current axes.
function violinplot(data: Tensor, options?: PlotOptions): void
data
Tensor
required
Data values
options
PlotOptions
Plot styling options

pie

Plot a pie chart on the current axes.
function pie(values: Tensor, labels?: readonly string[], options?: PlotOptions): void
values
Tensor
required
Slice values
labels
string[]
Optional labels for each slice
options
PlotOptions
Plot styling options
Example:
import { pie, tensor } from 'deepbox/plot';

const values = tensor([30, 25, 20, 15, 10]);
const labels = ['A', 'B', 'C', 'D', 'E'];
pie(values, labels);

Rendering

show

Render a figure to SVG or PNG.
function show(
  options?: { figure?: Figure; format?: "svg" | "png" }
): RenderedSVG | Promise<RenderedPNG>
options.figure
Figure
Figure to render (default: current figure)
options.format
string
Output format: 'svg' (default) or 'png'
Returns
RenderedSVG | Promise<RenderedPNG>
Rendered figure

saveFig

Save a figure to disk as SVG or PNG.
function saveFig(
  path: string,
  options?: { figure?: Figure; format?: "svg" | "png" }
): Promise<void>
path
string
required
Output file path (extension must match format)
options.figure
Figure
Figure to save (default: current figure)
options.format
string
Output format: 'svg' or 'png' (inferred from extension if not specified)

legend

Show or configure a legend on the current axes.
function legend(options?: LegendOptions): void
options
LegendOptions
Legend configuration options

Build docs developers (and LLMs) love