Skip to main content

diagram

lq.diagram(width: 6cm, height: 4cm, title: none, legend: (:), xlim: auto, ylim: auto, xlabel: none, ylabel: none, grid: auto, xscale: auto, yscale: auto, xaxis: (:), yaxis: (:), margin: 6%, aspect-ratio: none, cycle: petroff10, fill: none, bounds: "strict", ..children)(source)

Creates a new diagram containing all plots that are passed as arguments. A comprehensive list of available plot functions can be found at Plot Types.

All plots need to be wrapped in a diagram in order to be displayed.

#lq.diagram(
title: [Trigonometric Functions],
xlabel: $x$,
ylabel: $y$,
lq.plot(lq.linspace(0, 10), calc.sin),
lq.plot(lq.linspace(0, 10), x => calc.cos(x) / 2)
)
Parameters

width : length | relative | auto    default: 6cm

The width of the diagram. This can be one of the following:

  • A length, defining just the width of the data area, excluding axes, labels, title, etc. To set a length including everything, use 0% + length, see the next option.
  • A ratio or relative where the ratio part is relative to the width of the parent that the diagram is placed in. This includes axes, labels, title, etc. This is not allowed if the parent has an unbounded width, e.g., a page with width: auto.
  • Or auto in which case the width is computed automatically based on diagram.aspect-ratio.

height : length | relative | auto    default: 4cm

The height of the diagram. This can be one of the following:

  • A length, defining just the height of the data area, excluding axes, labels, title, etc. To set a length including everything, use 0% + length, see the next option.
  • A ratio or relative where the ratio part is relative to the height of the parent that the diagram is placed in. This includes axes, labels, title, etc. This is not allowed if the parent has an unbounded height, e.g., a page with height: auto.
  • Or auto in which case the height is computed automatically based on diagram.aspect-ratio.

title : lq.title | str | content | none    default: none

The title for the diagram. Use a title object for more options.

legend : none | dictionary | lq.legend    default: (:)

Options to pass to the legend constructor. If set to none, no legend is shown.

Alternatively, a legend with entirely custom entries can be created and given here.

xlim : auto | array    default: auto

Data limits along the xx-axis. Expects auto or a tuple (min, max) where min and max may individually be auto. Also see axis.lim.

ylim : auto | array    default: auto

Data limits along the yy-axis. Expects auto or a tuple (min, max) where min and max may individually be auto. Also see axis.lim.

xlabel : lq.label | content    default: none

Label for the xx-axis. Use a label object for more options.

ylabel : lq.label | content    default: none

Label for the yy-axis. Use a label object for more options.

grid : auto | none | dictionary | stroke | color | length    default: auto

Options to apply to the grid. A stroke, color, or length argument directly sets the grid stroke while a dictionary with the possible keys stroke, stroke-sub, and z-index gives more fine-grained control. Setting this parameter to none removes the grid entirely. See grid for more details.

xscale : auto | str | lq.scale    default: auto

Sets the scale of the xx-axis. This may be a scale object or the name of one of the built-in scales "linear", "log", "symlog", and "datetime".

If left at auto, the scale will be set to "datetime" if any of the plots uses datetime coordinates and "linear" otherwise.

yscale : auto | str | lq.scale    default: auto

Sets the scale of the yy-axis. This may be a scale object or the name of one of the built-in scales "linear", "log", "symlog", and "datetime".

If left at auto, the scale will be set to "datetime" if any of the plots uses datetime coordinates and "linear" otherwise.

xaxis : none | dictionary    default: (:)

Configures the xx-axis through a dictionary of arguments to pass to the constructor of the axis. See axis for available options. Setting this to none hides the axis by effectively setting axis.hidden to true.

yaxis : none | dictionary    default: (:)

Configures the yy-axis through a dictionary of arguments to pass to the constructor of the axis. See axis for available options. Setting this to none hides the axis by effectively setting axis.hidden to true.

margin : ratio | dictionary    default: 6%

Configures the automatic margins of the diagram around the data. If set to 0%, the outer-most data points align tightly with the edges of the diagram (as long as the axis limits are left at auto). Otherwise, the margins are computed in percent of the covered range along an axis (in scaled coordinates).

The margins can be set individually for each side by passing a dictionary with the possible keys

  • left, right, top, bottom for addressing individual sides,
  • x, y for left/right and top/bottom combined sides, and
  • rest for all sides not specified by any of the above.

aspect-ratio : none | float    default: none

Fixes the aspect ratio of data coordinates. For example, when plotting a graph, fixing the aspect ratio ensures that a unit distance on the x-axis is visually equal to a unit distance on the y-axis. This is particularly useful for visualizing data where the relative proportions are important, such as in scatter plots or heatmaps.

After setting an aspect ratio there are two ways how it can be realized.

  1. By adjusting the dimensions of the diagram area, i.e., the width or height. Select this method by setting one of diagram.width and diagram.height to auto.
  2. By adjusting the margins of the diagram. Select this method by leaving both diagram.width and diagram.height at fixed (relative) lengths.

cycle : array    default: petroff10

Style cycle to use for this diagram. Check out the cycles tutorial for more information. The elements of a cycle array should either be

  • all of type color (e.g., one of the maps from lq.color.map), or
  • all of type dictionary with possible keys color, stroke, and mark, or
  • all of type function as described in the tutorial.

fill : none | color | gradient | tiling    default: none

How to fill the background of the data area.

bounds : "relaxed" | "strict" | "data-area"    default: "strict"

How to compute the bounding box of a diagram. See also the tutorial Plot grids − Strict or relaxed bounds?.

  • "strict": The bounds are computed as the precise bounding box of the diagram. The exact behavior for text bounds also depends on the setting of text.top-edge and text.bottom-edge.
  • "relaxed": Tick labels of a horizontal axis are allowed to hang into the page margins at the right and left of a diagram and tick labels of a vertical axis may spill out at the top and bottom. Like this, the spines can line up with the main text body, even when the first and last tick sit on the far edges of an axis. Sometimes, this can give a cleaner look.
  • "data-area": The bounds are simply the data area.

..children : any

Plot objects like plot, bar, scatter, contour etc. and additional axis objects.