Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction to ax-plots

Interactive Plotly.js plotting for Maxima via Aximar. Provides functions that reuse Maxima’s draw package object syntax (explicit, parametric, points, implicit) and add new objects (lines) for data plotting. Renders with Plotly instead of gnuplot. Lists and ndarrays (from the numerics package) are accepted transparently.

To use the package:

load("ax-plots");

2D Plotting


ax_plot2d (y1, x1, y2, x2, …, options) — Function

Plot expressions and/or data as interactive Plotly.js line charts. Arguments are consumed as (y, x) pairs, where y is what to plot and x is the domain.

Each pair can be:

  • Expression + range: y is an expression (or list of expressions), x is [var, min, max]
  • Data + data: y is a list or ndarray of values, x is a list or ndarray of coordinates

Calling forms:

  • ax_plot2d(expr, [var, min, max]) — single expression
  • ax_plot2d([expr_1, ..., expr_n], [var, min, max]) — multiple expressions sharing a range
  • ax_plot2d(ys, xs) — data pair (lists or ndarrays), plotted as lines
  • ax_plot2d([ys_1, ..., ys_n], xs) — multiple y series sharing one x
  • ax_plot2d(expr, [var, lo, hi], ys, xs, ...) — mixed expressions and data

Examples

/* Single expression */
ax_plot2d(sin(x), [x, -%pi, %pi])$

/* Multiple expressions */
ax_plot2d([sin(x), cos(x)], [x, -5, 5])$

/* Data from lists */
ax_plot2d([1,4,9,16], [1,2,3,4])$

/* Data from ndarrays (requires numerics package) */
xs : np_linspace(-3, 3, 50)$
ax_plot2d(np_mul(xs, xs), xs)$

/* Apply a custom function with np_map */
f(x) := x^3 - x$
ax_plot2d(np_map(f, xs), xs)$

/* Or use a lambda for quick one-off transforms */
ax_plot2d(np_map(lambda([x], x^3 - x), xs), xs)$

/* Multiple y series sharing x */
ax_plot2d([np_pow(xs, 2), np_sin(xs)], xs)$

/* Mixed expressions and data */
ax_plot2d(sin(x), [x, -3, 3], np_pow(xs, 2), xs, title="Mixed")$

/* With options */
ax_plot2d(x^2, [x, -3, 3], title="Parabola", color="red")$

Style Options

Style options apply to subsequent traces until overridden:

OptionDefaultDescription
colorautoLine/marker color (atom like red or CSS string)
line_width2Line width in pixels
dash"solid"Line style: "solid", "dot", "dash", "dashdot"
opacity1.0Trace opacity (0–1)
nameautoLegend entry name
nticks500Sampling resolution

Layout Options

OptionDescription
titlePlot title
xlabel / ylabelAxis labels
xrange / yrangeAxis ranges, e.g. xrange=[-5,5]
gridShow grid lines (true/false)
showlegendShow legend (true/false)
aspect_ratioLock aspect ratio (true/false)
widthFixed plot width in pixels
heightFixed plot height in pixels

See also: ax_draw2d, ax_draw3d, ax_polar, plot2d


ax_draw2d ([args]) — Function

Draw 2D interactive plots using Plotly.js. Accepts Maxima draw package objects and Aximar-specific objects, rendering them as interactive charts with pan, zoom, and hover.

Supported Objects

Draw package objects:

ObjectSyntaxDescription
explicitexplicit(expr, var, lo, hi)A curve y=f(x)
parametricparametric(x(t), y(t), t, tlo, thi)A parametric curve
pointspoints([[x1,y1],...]) or points(xs, ys)Scatter points
lineslines([[x1,y1],...]) or lines(xs, ys)Line plot from data
implicitimplicit(eqn, x, xlo, xhi, y, ylo, yhi)An implicit curve f(x,y)=0

Aximar objects:

ObjectSyntaxDescription
ax_contourax_contour(expr, x, xlo, xhi, y, ylo, yhi)Filled contour plot
ax_heatmapax_heatmap(matrix) or ax_heatmap(expr, x, xlo, xhi, y, ylo, yhi)Heatmap
ax_barax_bar(categories, values) or ax_bar(values)Bar chart
ax_histogramax_histogram(data)Histogram
ax_vector_fieldax_vector_field(Fx, Fy, x, xlo, xhi, y, ylo, yhi)2D vector field
ax_streamlineax_streamline(Fx, Fy, x, xlo, xhi, y, ylo, yhi)Streamline / phase portrait curves

Examples

/* Explicit curves with styling */
ax_draw2d(
  color="red", explicit(x^2, x, -3, 3),
  color="blue", explicit(x^3, x, -2, 2)
)$

/* Filled contour */
ax_draw2d(
  ax_contour(sin(x)*cos(y), x, -%pi, %pi, y, -%pi, %pi),
  colorscale="Viridis", title="Contour Plot"
)$

/* Bar chart */
ax_draw2d(
  ax_bar(["Q1","Q2","Q3","Q4"], [100,150,120,180]),
  title="Quarterly Sales"
)$

/* Histogram */
ax_draw2d(
  ax_histogram(makelist(random(100)/10.0, i, 1, 500)),
  nbins=20, title="Distribution"
)$

/* Line plot from data */
ax_draw2d(lines([1,2,3,4,5], [1,4,9,16,25]))$

/* Scatter with separate x/y lists */
ax_draw2d(points([1,2,3,4,5], [1,4,9,16,25]))$

/* Lines and points accept ndarrays (requires numerics package) */
xs : np_linspace(-3, 3, 50)$
ax_draw2d(
  lines(xs, np_mul(xs, xs)),
  points(xs, np_sin(xs))
)$

/* Use np_map with a lambda for custom transforms */
ax_draw2d(lines(xs, np_map(lambda([x], x^3 - x), xs)))$

/* Phase portrait: vector field + streamlines */
ax_draw2d(
  color="#cccccc", ax_vector_field(-y, x, x, -3, 3, y, -3, 3),
  color="red", ax_streamline(-y, x, x, -3, 3, y, -3, 3),
  aspect_ratio=true, title="Phase Portrait"
)$

/* Streamlines with custom initial conditions */
ax_draw2d(
  initial_points=[[1,0],[0,1],[-1,0],[0,-1]],
  t_range=[0,8],
  ax_streamline(-y, x, x, -3, 3, y, -3, 3),
  aspect_ratio=true
)$

Style Options

Options use Plotly-native naming and apply to subsequent objects until overridden:

OptionDefaultDescription
colorautoLine/marker color (atom like red or CSS string)
fill_colornoneFill color
opacity1.0Trace opacity (0–1)
line_width2Line width in pixels
dash"solid"Line style: "solid", "dot", "dash", "dashdot"
marker_symbol"circle"Marker shape
marker_size6Marker size
nameautoLegend entry
fillnoneFill region: "tozeroy", "toself", etc.
colorscalenoneColor scale for contour/heatmap (e.g. "Viridis", "Hot")
showscaleautoShow/hide colorbar for contour/heatmap
ncontoursautoNumber of contour levels (ax_contour)
nbinsautoNumber of bins (ax_histogram)
bar_widthautoBar width fraction (ax_bar)
nticks500Sampling resolution
ngrid20Vector field grid resolution (ngrid x ngrid)
arrow_scale1.0Arrow length multiplier (ax_vector_field)
normalizefalseEqual-length arrows, direction only (ax_vector_field)
initial_pointsautoStreamline start points [[x0,y0],...] (ax_streamline)
t_range[0, 10]Integration time span [t0, tf] (ax_streamline)
dt0.05RK4 step size (ax_streamline)

Layout Options

OptionDescription
titlePlot title
xlabel / ylabelAxis labels
xrange / yrangeAxis ranges
gridShow grid lines
xaxis / yaxisShow/hide axes
showlegendShow legend
aspect_ratioLock aspect ratio
widthFixed plot width in pixels
heightFixed plot height in pixels
bar_modeBar/histogram grouping: "group", "stack", "overlay"

See also: ax_plot2d, ax_draw3d, ax_polar, draw2d


ax_polar (expr, [var, min, max]) — Function

Plot r(θ) curves in polar coordinates as interactive Plotly.js charts. Standalone function (like ax_plot2d).

Calling forms:

  • ax_polar(expr, [θ, min, max], options) — single expression
  • ax_polar([expr_1, ..., expr_n], [θ, min, max], options) — multiple expressions

Examples

/* Cardioid */
ax_polar(1 + cos(θ), [θ, 0, 2*%pi])$

/* Rose curve */
ax_polar(sin(3*θ), [θ, 0, 2*%pi], color="red", title="Rose Curve")$

/* Multiple curves */
ax_polar(
  [1 + cos(θ), 1 - cos(θ)],
  [θ, 0, 2*%pi],
  title="Cardioids"
)$

/* Spiral */
ax_polar(θ/10, [θ, 0, 6*%pi], title="Archimedean Spiral")$

Style Options

OptionDefaultDescription
colorautoLine color
line_width2Line width in pixels
dash"solid"Line style: "solid", "dot", "dash", "dashdot"
nameautoLegend entry
opacity1.0Trace opacity
nticks500Sampling resolution

Layout Options

OptionDescription
titlePlot title
showlegendShow legend (true/false)
widthFixed plot width in pixels
heightFixed plot height in pixels

See also: ax_plot2d, ax_draw2d

3D Plotting


ax_draw3d ([args]) — Function

Draw 3D interactive plots using Plotly.js with WebGL rendering. Produces rotatable, zoomable 3D charts.

Supported Draw Objects

ObjectSyntaxDescription
explicitexplicit(expr, x, xlo, xhi, y, ylo, yhi)A surface z=f(x,y)
pointspoints([[x1,y1,z1],...]) or points(xs, ys, zs)3D scatter points
lineslines([[x1,y1,z1],...]) or lines(xs, ys, zs)3D line plot from data

Examples

/* 3D surface */
ax_draw3d(explicit(sin(x)*cos(y), x, -%pi, %pi, y, -%pi, %pi))$

/* 3D scatter */
ax_draw3d(points([[1,1,1],[2,2,4],[3,3,9]]), marker_size=5)$

/* 3D scatter with separate coordinate arrays */
ax_draw3d(points([1,2,3], [4,5,6], [7,8,9]))$

/* 3D line plot from data */
ax_draw3d(lines([[0,0,0],[1,1,1],[2,0,2]]))$

/* 3D line from separate arrays (e.g. ndarrays) */
t : np_linspace(0, 6.28, 200)$
ax_draw3d(lines(np_cos(t), np_sin(t), np_scale(0.1, t)))$

/* With options */
ax_draw3d(
  explicit(x^2 - y^2, x, -2, 2, y, -2, 2),
  title="Saddle Surface",
  colorscale="Viridis"
)$

Style Options

OptionDefaultDescription
colorautoTrace color
opacity1.0Trace opacity
colorscalenoneSurface colorscale (e.g. "Viridis", "Hot")
marker_size6Marker size for scatter points
marker_symbol"circle"Marker shape
nameautoLegend entry
nticks50Grid resolution (nticks x nticks)

Layout Options

OptionDescription
titlePlot title
xlabel / ylabel / zlabelAxis labels
xrange / yrange / zrangeAxis ranges
showlegendShow legend
widthFixed plot width in pixels
heightFixed plot height in pixels

See also: ax_plot2d, ax_draw2d, ax_polar, draw3d

Statistical Charts


ax_bar (categories, values) — Function

Bar chart for labeled or numeric data. Use inside ax_draw2d.

Calling forms:

  • ax_bar(categories, values) — string category list + numeric value list
  • ax_bar(values) — just values (auto-numbered 1, 2, 3, …)

For multiple series, use different name options and bar_mode layout option.

Examples

/* Basic bar chart */
ax_draw2d(
  ax_bar(["Q1","Q2","Q3","Q4"], [100,150,120,180]),
  title="Quarterly Sales"
)$

/* Colored bars */
ax_draw2d(
  color="steelblue", ax_bar(["A","B","C"], [10,20,30]),
  title="Categories"
)$

/* Grouped bars (multiple series) */
ax_draw2d(
  name="2024", ax_bar(["Q1","Q2","Q3"], [100,150,120]),
  name="2025", ax_bar(["Q1","Q2","Q3"], [110,160,140]),
  bar_mode="group", title="Year Comparison"
)$

/* Stacked bars */
ax_draw2d(
  name="Product A", ax_bar(["Jan","Feb","Mar"], [30,40,35]),
  name="Product B", ax_bar(["Jan","Feb","Mar"], [20,25,30]),
  bar_mode="stack"
)$

Relevant Options

OptionDefaultDescription
colorautoBar fill color
bar_widthautoBar width (0–1 fraction)
nameautoLegend entry / series name
opacity1.0Bar opacity

Layout Options

OptionValuesDescription
bar_mode"group", "stack", "overlay"How multiple bar series are arranged

See also: ax_draw2d, ax_histogram


ax_histogram (data) — Function

Histogram of numeric data. Use inside ax_draw2d. Takes a flat list of numbers; Plotly handles binning automatically.

Examples

/* Basic histogram */
data: makelist(random(100)/10.0, i, 1, 500)$
ax_draw2d(ax_histogram(data), title="Distribution")$

/* Control bin count */
ax_draw2d(ax_histogram(data), nbins=30)$

/* Overlaid histograms */
data1: makelist(random_normal(0, 1), i, 1, 500)$
data2: makelist(random_normal(2, 1.5), i, 1, 500)$
ax_draw2d(
  color="blue", opacity=0.5, name="Group A", ax_histogram(data1),
  color="red", opacity=0.5, name="Group B", ax_histogram(data2),
  bar_mode="overlay", title="Comparing Distributions"
)$

Relevant Options

OptionDefaultDescription
nbinsautoNumber of bins
colorautoBar fill color
nameautoLegend entry
opacity1.0Bar opacity

Layout Options

OptionValuesDescription
bar_mode"group", "stack", "overlay"How overlapping histograms are displayed

See also: ax_draw2d, ax_bar


ax_heatmap (z_matrix) — Function

Heatmap visualization. Use inside ax_draw2d.

Calling forms:

  • ax_heatmap(z_matrix) — pass a Maxima matrix(...) directly
  • ax_heatmap(z_matrix, x_labels, y_labels) — matrix with string lists for axis labels
  • ax_heatmap(expr, xvar, xlo, xhi, yvar, ylo, yhi) — symbolic expression sampled on a grid

Examples

/* From a matrix */
ax_draw2d(ax_heatmap(matrix([1,2,3],[4,5,6],[7,8,9])))$

/* With axis labels */
M: matrix([85,90,78],[92,88,95])$
ax_draw2d(
  ax_heatmap(M, ["Math","Science","English"], ["Alice","Bob"]),
  colorscale="Blues", title="Scores"
)$

/* From an expression */
ax_draw2d(
  ax_heatmap(sin(x)*cos(y), x, -%pi, %pi, y, -%pi, %pi),
  colorscale="Hot"
)$

Relevant Options

OptionDefaultDescription
colorscaleautoColor scale: "Viridis", "Hot", "Blues", etc.
showscaleautoShow/hide the color bar
nticks50Grid resolution (expression form only)
nameautoLegend entry
opacity1.0Trace opacity

See also: ax_draw2d, ax_contour

Field Plots


ax_contour (expr, xvar, xlo, xhi, yvar, ylo, yhi) — Function

Filled contour plot of a 2D expression. Use inside ax_draw2d. Samples f(x,y) on a grid and renders as a Plotly contour chart with multiple filled levels.

Distinct from implicit() which renders a single contour line at f(x,y)=0.

Examples

/* Basic contour plot */
ax_draw2d(ax_contour(x^2 + y^2, x, -3, 3, y, -3, 3))$

/* With colorscale and contour count */
ax_draw2d(
  ax_contour(sin(x)*cos(y), x, -%pi, %pi, y, -%pi, %pi),
  colorscale="Viridis", ncontours=20,
  title="sin(x)*cos(y)"
)$

/* Hide colorbar */
ax_draw2d(
  ax_contour(x*y, x, -2, 2, y, -2, 2),
  showscale=false
)$

Relevant Options

OptionDefaultDescription
colorscaleautoColor scale: "Viridis", "Hot", "Blues", etc.
ncontoursautoNumber of contour levels
showscaleautoShow/hide the color bar
nticks80Grid sampling resolution
nameautoLegend entry
opacity1.0Trace opacity

See also: ax_draw2d, ax_heatmap, implicit


ax_vector_field (Fx, Fy, xvar, xlo, xhi, yvar, ylo, yhi) — Function

2D vector field (quiver) plot. Use inside ax_draw2d. Given a vector field F = (Fx(x,y), Fy(x,y)), samples on a grid and renders arrows showing the field direction and magnitude.

Examples

/* Rotation field */
ax_draw2d(ax_vector_field(-y, x, x, -3, 3, y, -3, 3))$

/* Source/sink */
ax_draw2d(
  ax_vector_field(x, y, x, -2, 2, y, -2, 2),
  title="Source"
)$

/* Direction-only (normalized arrows) */
ax_draw2d(
  ax_vector_field(-y, x, x, -3, 3, y, -3, 3),
  normalize=true, ngrid=25
)$

/* Phase portrait: vector field + streamlines */
ax_draw2d(
  color="#cccccc", ax_vector_field(-y, x, x, -3, 3, y, -3, 3),
  color="red", ax_streamline(-y, x, x, -3, 3, y, -3, 3),
  aspect_ratio=true, title="Phase Portrait"
)$

Relevant Options

OptionDefaultDescription
ngrid20Grid resolution (ngrid x ngrid arrows)
arrow_scale1.0Multiplier for arrow length
normalizefalseEqual-length arrows (direction only)
colorautoArrow color
nameautoLegend entry
opacity1.0Trace opacity

See also: ax_draw2d, ax_streamline


ax_streamline (Fx, Fy, xvar, xlo, xhi, yvar, ylo, yhi) — Function

Streamline / phase portrait curves for a 2D ODE system dx/dt = Fx(x,y), dy/dt = Fy(x,y). Use inside ax_draw2d. Integrates trajectories from initial points using RK4.

Combine with ax_vector_field for a full phase portrait:

ax_draw2d(
  color="#cccccc", ax_vector_field(-y, x, x, -3, 3, y, -3, 3),
  color="red", ax_streamline(-y, x, x, -3, 3, y, -3, 3),
  aspect_ratio=true, title="Phase Portrait"
)$

Examples

/* Auto initial points */
ax_draw2d(ax_streamline(-y, x, x, -3, 3, y, -3, 3))$

/* Custom initial points and time range */
ax_draw2d(
  initial_points=[[0.5,0.5],[2,2],[3,1]],
  t_range=[0,20], dt=0.01,
  ax_streamline(x*(1-y), y*(x-1), x, 0, 4, y, 0, 4),
  title="Lotka-Volterra"
)$

Relevant Options

OptionDefaultDescription
initial_pointsautoList of [x0,y0] starting points
t_range[0, 10]Integration time span [t0, tf]
dt0.05RK4 step size
colorautoCurve color
line_width1.5Curve thickness
nameautoLegend entry
opacity1.0Trace opacity

See also: ax_draw2d, ax_vector_field