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 expressionax_plot2d([expr_1, ..., expr_n], [var, min, max])— multiple expressions sharing a rangeax_plot2d(ys, xs)— data pair (lists or ndarrays), plotted as linesax_plot2d([ys_1, ..., ys_n], xs)— multiple y series sharing one xax_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:
| Option | Default | Description |
|---|---|---|
color | auto | Line/marker color (atom like red or CSS string) |
line_width | 2 | Line width in pixels |
dash | "solid" | Line style: "solid", "dot", "dash", "dashdot" |
opacity | 1.0 | Trace opacity (0–1) |
name | auto | Legend entry name |
nticks | 500 | Sampling resolution |
Layout Options
| Option | Description |
|---|---|
title | Plot title |
xlabel / ylabel | Axis labels |
xrange / yrange | Axis ranges, e.g. xrange=[-5,5] |
grid | Show grid lines (true/false) |
showlegend | Show legend (true/false) |
aspect_ratio | Lock aspect ratio (true/false) |
width | Fixed plot width in pixels |
height | Fixed 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:
| Object | Syntax | Description |
|---|---|---|
explicit | explicit(expr, var, lo, hi) | A curve y=f(x) |
parametric | parametric(x(t), y(t), t, tlo, thi) | A parametric curve |
points | points([[x1,y1],...]) or points(xs, ys) | Scatter points |
lines | lines([[x1,y1],...]) or lines(xs, ys) | Line plot from data |
implicit | implicit(eqn, x, xlo, xhi, y, ylo, yhi) | An implicit curve f(x,y)=0 |
Aximar objects:
| Object | Syntax | Description |
|---|---|---|
ax_contour | ax_contour(expr, x, xlo, xhi, y, ylo, yhi) | Filled contour plot |
ax_heatmap | ax_heatmap(matrix) or ax_heatmap(expr, x, xlo, xhi, y, ylo, yhi) | Heatmap |
ax_bar | ax_bar(categories, values) or ax_bar(values) | Bar chart |
ax_histogram | ax_histogram(data) | Histogram |
ax_vector_field | ax_vector_field(Fx, Fy, x, xlo, xhi, y, ylo, yhi) | 2D vector field |
ax_streamline | ax_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:
| Option | Default | Description |
|---|---|---|
color | auto | Line/marker color (atom like red or CSS string) |
fill_color | none | Fill color |
opacity | 1.0 | Trace opacity (0–1) |
line_width | 2 | Line width in pixels |
dash | "solid" | Line style: "solid", "dot", "dash", "dashdot" |
marker_symbol | "circle" | Marker shape |
marker_size | 6 | Marker size |
name | auto | Legend entry |
fill | none | Fill region: "tozeroy", "toself", etc. |
colorscale | none | Color scale for contour/heatmap (e.g. "Viridis", "Hot") |
showscale | auto | Show/hide colorbar for contour/heatmap |
ncontours | auto | Number of contour levels (ax_contour) |
nbins | auto | Number of bins (ax_histogram) |
bar_width | auto | Bar width fraction (ax_bar) |
nticks | 500 | Sampling resolution |
ngrid | 20 | Vector field grid resolution (ngrid x ngrid) |
arrow_scale | 1.0 | Arrow length multiplier (ax_vector_field) |
normalize | false | Equal-length arrows, direction only (ax_vector_field) |
initial_points | auto | Streamline start points [[x0,y0],...] (ax_streamline) |
t_range | [0, 10] | Integration time span [t0, tf] (ax_streamline) |
dt | 0.05 | RK4 step size (ax_streamline) |
Layout Options
| Option | Description |
|---|---|
title | Plot title |
xlabel / ylabel | Axis labels |
xrange / yrange | Axis ranges |
grid | Show grid lines |
xaxis / yaxis | Show/hide axes |
showlegend | Show legend |
aspect_ratio | Lock aspect ratio |
width | Fixed plot width in pixels |
height | Fixed plot height in pixels |
bar_mode | Bar/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 expressionax_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
| Option | Default | Description |
|---|---|---|
color | auto | Line color |
line_width | 2 | Line width in pixels |
dash | "solid" | Line style: "solid", "dot", "dash", "dashdot" |
name | auto | Legend entry |
opacity | 1.0 | Trace opacity |
nticks | 500 | Sampling resolution |
Layout Options
| Option | Description |
|---|---|
title | Plot title |
showlegend | Show legend (true/false) |
width | Fixed plot width in pixels |
height | Fixed 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
| Object | Syntax | Description |
|---|---|---|
explicit | explicit(expr, x, xlo, xhi, y, ylo, yhi) | A surface z=f(x,y) |
points | points([[x1,y1,z1],...]) or points(xs, ys, zs) | 3D scatter points |
lines | lines([[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
| Option | Default | Description |
|---|---|---|
color | auto | Trace color |
opacity | 1.0 | Trace opacity |
colorscale | none | Surface colorscale (e.g. "Viridis", "Hot") |
marker_size | 6 | Marker size for scatter points |
marker_symbol | "circle" | Marker shape |
name | auto | Legend entry |
nticks | 50 | Grid resolution (nticks x nticks) |
Layout Options
| Option | Description |
|---|---|
title | Plot title |
xlabel / ylabel / zlabel | Axis labels |
xrange / yrange / zrange | Axis ranges |
showlegend | Show legend |
width | Fixed plot width in pixels |
height | Fixed 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 listax_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
| Option | Default | Description |
|---|---|---|
color | auto | Bar fill color |
bar_width | auto | Bar width (0–1 fraction) |
name | auto | Legend entry / series name |
opacity | 1.0 | Bar opacity |
Layout Options
| Option | Values | Description |
|---|---|---|
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
| Option | Default | Description |
|---|---|---|
nbins | auto | Number of bins |
color | auto | Bar fill color |
name | auto | Legend entry |
opacity | 1.0 | Bar opacity |
Layout Options
| Option | Values | Description |
|---|---|---|
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 Maximamatrix(...)directlyax_heatmap(z_matrix, x_labels, y_labels)— matrix with string lists for axis labelsax_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
| Option | Default | Description |
|---|---|---|
colorscale | auto | Color scale: "Viridis", "Hot", "Blues", etc. |
showscale | auto | Show/hide the color bar |
nticks | 50 | Grid resolution (expression form only) |
name | auto | Legend entry |
opacity | 1.0 | Trace 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
| Option | Default | Description |
|---|---|---|
colorscale | auto | Color scale: "Viridis", "Hot", "Blues", etc. |
ncontours | auto | Number of contour levels |
showscale | auto | Show/hide the color bar |
nticks | 80 | Grid sampling resolution |
name | auto | Legend entry |
opacity | 1.0 | Trace 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
| Option | Default | Description |
|---|---|---|
ngrid | 20 | Grid resolution (ngrid x ngrid arrows) |
arrow_scale | 1.0 | Multiplier for arrow length |
normalize | false | Equal-length arrows (direction only) |
color | auto | Arrow color |
name | auto | Legend entry |
opacity | 1.0 | Trace 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
| Option | Default | Description |
|---|---|---|
initial_points | auto | List of [x0,y0] starting points |
t_range | [0, 10] | Integration time span [t0, tf] |
dt | 0.05 | RK4 step size |
color | auto | Curve color |
line_width | 1.5 | Curve thickness |
name | auto | Legend entry |
opacity | 1.0 | Trace opacity |
See also: ax_draw2d, ax_vector_field