Skip to main content

plot

lq.plot(x, y, xerr=none, yerr=none, color=auto, stroke=auto, mark=auto, mark-size=auto, mark-color=auto, step=none, every=none, label=none, clip=true, z-index=2)

Standard plotting method for 2d data with lines and/or marks and optional error bars. Points where the xx or yy coordinate is nan are skipped.

#let x = lq.linspace(0, 10)

#lq.diagram(
lq.plot(x, x.map(x => calc.sin(x)))
)

By default, the line and mark style is determined by the current diagram.cycle. However, they can be configured per plot with the options plot.color, plot.mark, and plot.stroke.

This function is also intended for creating plots with error bars. Those can be styled through errorbar.

#lq.diagram(
lq.plot(
range(8), (3, 6, 2, 6, 5, 9, 0, 4),
yerr: (1, 1, .7, .8, .2, .6, .5, 1),
stroke: none,
mark: "star",
mark-size: 6pt
)
)
Parameters

x : array

An array of xx data coordinates. Data coordinates need to be of type int or float.

y : array

An array of yy data coordinates. The number of xx and yy coordinates must match.

xerr : none | array | dictionary    default: none

Optional errors/uncertainties for xx coordinates. Symmetric errors can be specified as a

  • a constant (e.g., xerr: 1.5) or
  • an array with the same length as plot.x for individual errors per data point (e.g., xerr: (0.5, 1, 1.5)).

Asymmetric errors can be given as

  • a dictionary with the keys p (plus) and m (minus) with either a constant value or arrays with the same length as plot.x (e.g., xerr: (p: 1, m: 2)) or
  • an array of dictionaries per data point, each filled with single p and m values (e.g., xerr: ((p: 1, m: 2), (p: 2, m: 3))).

The look of the error bars can be controlled through errorbar.

yerr : none | array    default: none

Optional errors/uncertainties for yy coordinates. See plot.xerr.

The look of the error bars can be controlled through errorbar.

color : auto | color    default: auto

Combined color for line and marks. See also the parameters plot.stroke and plot.mark-fill which take precedence over color, if set.

stroke : auto | stroke    default: auto

The line style to use for this plot (takes precedence over plot.color).

mark : auto | lq.mark | string    default: auto

The mark to use to mark data points. This may either be a mark (such as lq.mark.x) or a registered mark string, see mark.

mark-size : auto | length    default: auto

Size of the marks. For variable-size mark plots, use the plot type scatter.

mark-color : auto | color    default: auto

Color of the marks (takes precedence over plot.color). TODO: this parameter should eventually be removed. Instead one would be able to set mark color and stroke through

#lq.diagram(
plot(..), // normal plot
{
set mark(fill: red, stroke: black)
plot(..)
}
)

This again reduces the API. mark.size however is common enough to deserve its own parameter.

step : none | start | end | center    default: none

Step mode for plotting the lines.

  • none: Consecutive data points are connected with a straight line.
  • start: The interval (xi1,xi](x_{i-1}, x_i] takes the value of xix_i.
  • center: The value switches half-way between consecutive xx positions.
  • end: The interval [xi,xi+1)[x_i, x_{i+1}) takes the value of xix_i.
Details
#import "@preview/lilaq:0.2.0" as lq

#lq.diagram(
lq.plot(
range(8), (3,6,2,6,5,9,0,4),
step: center
)
)

every : none | int | array | dict    default: none

Specifies the interval of marks to plot. This can be used to skip marks while still drawing lines between all points.

  • none: All marks are plotted.
  • int: Every nn-th mark is plotted.
  • array: All marks with the given indices are plotted.
  • dict: A dictionary with the keys n, start (start index), and end (end index, negative indices count from the end) can be used to specify a range of marks to plot.
Details
#lq.diagram(
lq.plot(
range(20),
range(20).map(x => x*x),
every: 4
)
)

label : any    default: none

The legend label for this plot. If not given, the plot will not appear in the legend.

clip : bool    default: true

Whether to clip the plot to the data area. This is usually a good idea for plots with lines but it does also clip part of marks that lie right on an axis.

Details

Comparison between clipped and non-clipped plot.

#lq.diagram(
margin: 0%,
lq.plot(
(1, 2, 3), (2.5, 1.9, 1.5),
mark: "o",
),
lq.plot(
(1, 2, 3), (1, 2.1, 3),
mark: "o",
clip: false
)
)

z-index : int | float    default: 2

Specifies the zz position of this plot in the order of rendered diagram objects. This makes it also possible to render plots in front of the axes which have a z-index of 2.1.

Details

In this example, the points are listed before the bars in the legend but they are still drawn in front of the bars.

#lq.diagram(
legend: (position: bottom),
lq.plot(
(1, 2, 3, 4), (2, 3, 4, 5),
mark-size: 10pt,
z-index: 2.01,
label: [Points],
),
lq.bar(
(1, 2, 3, 4), (2, 3, 4, 5),
label: [Bars],
)
)