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


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