bar
lq.bar(x, y, fill=auto, stroke=none, align=center, width=0.8, offset=0, base=0, label=none, clip=true, z-index=2)
Creates a bar plot from the given data.
#lq.diagram(
xaxis: (subticks: none),
lq.bar(
(1, 2, 3, 4, 5, 6),
(1, 2, 3, 2, 5, 3),
)
)
The example below demonstrates how to use custom tick labels by passing
an array of (location, label)
tuples to axis.ticks
.
#lq.diagram(
xaxis: (
ticks: ("Apples", "Bananas", "Kiwis", "Mangos", "Papayas")
.map(rotate.with(-45deg, reflow: true))
.enumerate(),
subticks: none,
),
lq.bar(
range(5),
(5, 3, 4, 2, 1)
)
)
x : array
An array of coordinates specifying the bar positions.
y : array
An array of coordinates specifying the bar heights. The number of and coordinates must match.
fill : none
| color
| gradient
| tiling
| array
default: auto
How to fill the bars. This can be a single value applied to all bars or an array with the same length as the coordinate arrays.
stroke : auto
| none
| color
| length
| stroke
| gradient
| tiling
| dictionary
default: none
How to stroke the bars. All values allowed by the built-in rect
function are also allowed here, see
std.rect#stroke
.
In particular, note that by passing a dictionary, the individual sides
of the bars can be stroked independently.
align : left
| center
| right
default: center
Alignment of the bars at the values.
Details
Demonstration of the different alignment modes.
#lq.diagram(
xaxis: (subticks: none),
lq.bar(
(1,2,3,4,5), (1,2,3,4,5),
width: 0.2, fill: red,
align: left, label: "left"
),
lq.bar(
(1,2,3,4,5), (5,4,3,2,1),
width: 0.2, fill: blue,
align: right, label: "right"
),
lq.bar(
(1,2,3,4,5), (2.5,) * 5,
width: 0.2, fill: rgb("#AAEEAA99"),
align: center, label: "center"
),
)
width : int
| float
| array
default: 0.8
Width of the bars in data coordinates. The width can be set either to a constant for all bars or per-bar by passing an array with the same length as the coordinate arrays.
Details
Example for a bar plot with varying bar widths.
#lq.diagram(
lq.bar(
(1, 2, 3, 4, 5),
(1, 2, 3, 2, 5),
width: (1, 0.5, 1, 0.5, 1),
fill: orange,
)
)
offset : int
| float
default: 0
An offset to apply to all coordinates. This is equivalent to replacing
the array passed to bar.x
with x.map(x => x + offset)
. Using an offset
can be useful to avoid overlaps when plotting multiple bar plots into one
diagram.
base : int
| float
| array
default: 0
Defines the coordinate of the baseline of the bars. This can either be a constant value applied to all bars or it can be set per-bar by passing an array with the same length as the coordinate arrays.
Details
Bar plot with varying base.
#lq.diagram(
xaxis: (subticks: none),
lq.bar(
(1, 2, 3, 4, 5),
(1, 2, 3, 0, 5),
base: (0, 1, 2, -1, 0),
fill: white,
stroke: 0.7pt
)
)
label : content
default: none
The legend label for this plot. See plot.label
.
clip : bool
default: true
Whether to clip the plot to the data area. See plot.clip
.
z-index : int
| float
default: 2
Determines the position of this plot in the order of rendered diagram
objects. See plot.z-index
.