plot
lq.plot(x, y, xerr: none, yerr: none, color: auto, stroke: auto, mark: auto, mark-size: auto, mark-color: auto, step: none, smooth: false, every: none, tip: none, toe: none, label: none, clip: true, z-index: 2)(source)Standard plotting function for 2d data with lines and/or marks and optional
error bars. Points are given as separate arrays of and coordinates.
For convenience, plot.y also accepts a function argument which is then
automatically evaluated for all given coordinates. Both methods are
demonstrated below.
#let x = lq.linspace(0, 10)
#let y = x.map(x => calc.sin(0.1 * x * x))
#lq.diagram(
lq.plot(x, y),
lq.plot(x, x => calc.sin(x + 0.541))
)
Points where either the or coordinate is float.nan are skipped.
By default, the line and mark style is determined by the current
diagram.cycle. However, both 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.
Error bars can be styled through the errorbar type.
#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
)
)
x : array
An array of coordinates. Data coordinates need to be of type int or float.
y : array | function
Specifies either an array of coordinates or a function that takes an
x value and returns a corresponding y coordinate. The number of
and coordinates must match.
xerr : none | array | dictionary default: none
Optional errors/uncertainties for coordinates. Symmetric errors can be specified as a
- a constant (e.g.,
xerr: 1.5) or - an array with the same length as
plot.xfor 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) andm(minus), both with either a constant value or arrays with the same length asplot.x(e.g.,xerr: (p: 1, m: 2),xerr: (p: (1, 2), m: (2, 3)) or - an array of dictionaries per data point, each filled with single
pandmvalues (e.g.,xerr: ((p: 1, m: 2), (p: 2, m: 3))).
The look of the error bars can be controlled through the type errorbar.
yerr : none | array default: none
Optional errors/uncertainties for 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 they are set.
stroke : auto | stroke default: auto
The line style to use for this plot. Here, if the color component of the stroke is not auto, it overrides plot.color.
mark : auto | none | lq.mark | str default: auto
The mark to use to mark data points. This may either be a mark (such as
lq.marks.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
How to color the marks. This overrides 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 affecting how the lines are drawn.
none: Consecutive data points are connected with a straight line.start: The interval takes the value of .center: The value switches half-way between consecutive positions.end: The interval takes the value of .
Example
#import "@preview/lilaq:0.6.0" as lq
#lq.diagram(
lq.plot(
range(8), (3,6,2,6,5,9,0,4),
step: center
)
)
smooth : bool default: false
Interpolates the data set using Bézier splines instead of connecting the points with straight lines.
Note: If two or fewer points are given, linear interpolation is used.
Example
#import "@preview/lilaq:0.6.0" as lq
#lq.diagram(
lq.plot(
range(8), (3, 6, 2, 6, 5, 9, 0, 4),
smooth: true
)
)
every : none | int | array | dictionary 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 -th mark is plotted.array: All marks with the given indices are plotted.dictionary: A dictionary with the keysn,start(start index), andend(end index, negative indices count from the end) can be used to specify a range of marks to plot.
Example
#lq.diagram(
lq.plot(
range(20),
range(20).map(x => x*x),
every: 4
)
)
tip : none | tiptoe.mark default: none
Places an arrow tip on the plot line. This expects a mark as specified by the Tiptoe package.
toe : none | tiptoe.mark default: none
Places an arrow tail on the plot line. This expects a mark as specified by the Tiptoe package.
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.
Example
Comparison between clipped and non-clipped plots.
#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 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 20).
Details
Example
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],
)
)