Plotting a curve

RustFig can draw a graph for you: a function y = f(x), a parametric curve x(t), y(t), or the columns of a data file. The result is ordinary Fig objects, so it prints, exports and scales like the rest of the drawing and opens in xfig. xfig has no such mode; this is an addition.

A plot is one compound: the frame, the ticks with their numbers, an optional grid, the axis labels and the curve as polylines. Open the compound (see Compounds) to touch up one part. The plot's settings are kept in the compound's comment (a line starting rustfig-plot:), which Fig 3.2 files keep, so a plot can be edited again later, also after saving and opening.

Plot

Key y. The last button of the Drawing column, beside the library button; the same as the Edit menu's Plot curve... (Ctrl+Shift+P, Cmd+Shift+P on macOS).

Edit > Plot curve... opens the same dialog without placing a frame: the plot goes to the origin at the default size.

The Plot dialog

Choose what to draw:

The ranges of x and y can be left empty to fit the curve (the y range of a curve with poles ignores a few extreme values, so 1/x does not flatten everything else); the numbers are rounded to tick values. Numbers may be expressions such as 2*pi.

The dialog has four groups: Function (the mode, its fields, samples), Range (x and y, each with Logarithmic: powers of ten, the range must be positive), Axes and Labels.

Axes has a small table with the rows x axis and y axis and the columns Ticks and Numbers: each box turns the tick marks or the numbers of that axis on or off by itself. Box draws the frame around the plot and Grid adds dotted lines at the numbered ticks. They are independent: with Box off the ticks still stand on the edges of the (invisible) frame. Plots made before these switches (one "axes" setting) open with Box, ticks and numbers all on, or all off if axes were off.

Labels holds the x and y label, plain text or LaTeX text with the TeX flag when LaTeX labels is on (they are then typeset when you export to LaTeX or turn on View > Typeset LaTeX text). LaTeX numbers writes the tick numbers as $...$ texts with the TeX flag too (a power of ten as $10^{-5}$, multiples of pi as $\pi$). LaTeX labels and numbers are texts in the LaTeX font with the TeX flag set: the canvas typesets them when TeX is installed (View > Typeset LaTeX text), and the LaTeX, pstex and pdftex exports pass them on unchanged.

x axis tick settings and y axis tick settings (collapsible, under Axes) set the details of each axis:

Too many ticks, a step of zero or less, and similar values are refused with an error. The settings are kept in the plot's comment like the rest.

The line style, thickness, colour, depth and the font of the numbers and labels are the current ones in the attribute panel; set them before you plot.

Expressions use + - * / ^ (also × ÷ and **), parentheses, the constants pi and e, and the functions sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, ln (also log: natural), log10, log2, sqrt, abs, floor, ceil, sign, and with two arguments atan2(y, x), min(a, b), max(a, b), pow(a, b). -x^2 means -(x^2) and 2^3^2 is 2^(3^2). An expression of up to 500 characters and nested up to 64 deep is accepted; an error names the position.

Where the function is not defined (division by zero, the root of a negative number) or beyond the plot's range, the curve simply stops: there is never a line across a pole such as that of 1/x or tan(x), and parts outside the frame are cut at the frame.

Edit plot

A plot stays one compound that carries the rustfig-plot: comment, and every part RustFig generated (the frame, grid lines, ticks, numbers, labels and the curve) carries a marker comment such as rustfig-plot-part: curve.

Commands

For scripts and MCP (see Automation): plot.add draws a plot (frame x, y, width, height; the settings mode, expr, xt, yt, tmin, tmax, file, xcol, ycol, data, xmin, xmax, ymin, ymax, samples, axes, grid, log_x, log_y, xlabel, ylabel, latex), plot.update changes some settings of an existing plot, plot.get returns them, plot.panel and plot.edit open the dialog. Hostile or huge input is refused with an error: the expression length, the number of samples (20,000), the points of the curve and the size of a data file are limited.