milia.plot.lets.draw#

Lets-plot primitives behind every figure (same signatures as milia.plot.mpl.draw).

Functions

accents()

Accent colours of the current style, for figure code.

band(frame, x, y, group, low, high[, ...])

Per-entity traces over a shaded band, entities leaving it highlighted.

bars(frame, x, y[, fill, facet, flip, ...])

Bar chart, dodged by fill, optionally horizontal and faceted.

dumbbell(frame, y, start, end[, title, ...])

Dumbbell chart: a start and end value per row, joined by a segment.

finish(plot, title, xlabel, ylabel[, ...])

Add reference lines, labels and the theme to a plot.

groups(frame, x, y, group[, highlight, ...])

Points of many groups, each outlined, numbered and given its own marker.

heat(frame, x, y, value[, text, title, ...])

Heatmap of a value over two categorical axes, optionally annotated.

hist(frame, x[, fill, vlines, bins, title, ...])

Histogram, optionally split by a column.

lines(frame, x, y[, color, facet, points, ...])

Line chart: one line per series, optionally one panel per facet.

ranges(frame, y, x, low, high[, title, ...])

Points with horizontal ranges, one row per item (e.g. ranks with intervals).

scatter(frame, x, y[, color, label, hlines, ...])

Scatter plot, optionally coloured and labelled.

strip(frame, x, y[, color, hlines, title, ...])

Jittered strip of values per category.

milia.plot.lets.draw.finish(plot, title, xlabel, ylabel, hlines=(), vlines=())#

Add reference lines, labels and the theme to a plot.

Parameters:
  • plot (Any) – A lets-plot PlotSpec.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

  • hlines – y values of dashed reference lines.

  • vlines – x values of dashed reference lines.

Return type:

Any

Returns:

The finished PlotSpec.

Examples

>>> import pandas as pd
>>> from lets_plot import aes, geom_point, ggplot
>>> plot = finish(
...     ggplot(pd.DataFrame({"x": [1]}), aes(x="x", y="x")) + geom_point(), "t", "x", "y", hlines=(1,)
... )
>>> len(plot.as_dict()["layers"])
2
milia.plot.lets.draw.lines(frame, x, y, color=None, facet=None, points=False, group=None, hlines=(), vlines=(), title=None, xlabel=None, ylabel=None, palette=None, widths=None)#

Line chart: one line per series, optionally one panel per facet.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Long-form data.

  • x (str) – x column.

  • y (str) – y column.

  • color (str | None) – Column splitting series.

  • facet (str | None) – Column splitting panels.

  • points (bool) – Also mark the points.

  • group (str | None) – Column grouping rows into separate lines within a series.

  • hlines (Sequence[float]) – y values of dotted reference lines.

  • vlines (Sequence[float]) – x values of dotted reference lines.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

  • palette (dict | None) – Fixed colour per series value.

  • widths (dict | None) – Line width per series value.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = lines(pd.DataFrame({"x": [0, 1], "y": [1.0, 2.0]}), "x", "y")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.bars(frame, x, y, fill=None, facet=None, flip=False, hlines=(), title=None, xlabel=None, ylabel=None)#

Bar chart, dodged by fill, optionally horizontal and faceted.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Long-form data.

  • x (str) – Category column.

  • y (str) – Value column.

  • fill (str | None) – Column splitting bars.

  • facet (str | None) – Column splitting panels.

  • flip (bool) – Draw horizontal bars.

  • hlines (Sequence[float]) – Values of reference lines.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = bars(pd.DataFrame({"x": ["a", "b"], "y": [1.0, 2.0]}), "x", "y")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.heat(frame, x, y, value, text=True, title=None, xlabel=None, ylabel=None)#

Heatmap of a value over two categorical axes, optionally annotated.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Long-form data.

  • x (str) – Column of the x category.

  • y (str) – Column of the y category.

  • value (str) – Column of the value.

  • text (bool) – Write each value in its cell.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = heat(pd.DataFrame({"a": ["x", "y"], "b": ["u", "u"], "v": [0.1, 0.9]}), "a", "b", "v")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.scatter(frame, x, y, color=None, label=None, hlines=(), vlines=(), title=None, xlabel=None, ylabel=None)#

Scatter plot, optionally coloured and labelled.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Data.

  • x (str) – x column.

  • y (str) – y column.

  • color (str | None) – Column colouring points.

  • label (str | None) – Column labelling points.

  • hlines (Sequence[float]) – y values of reference lines.

  • vlines (Sequence[float]) – x values of reference lines.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = scatter(pd.DataFrame({"x": [0.0, 1.0], "y": [1.0, 0.0]}), "x", "y")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.groups(frame, x, y, group, highlight=None, markers=True, numbers=True, outline=True, title=None, xlabel=None, ylabel=None)#

Points of many groups, each outlined, numbered and given its own marker.

Colour alone cannot identify many groups, so each group has a marker shape, a pale outline (the convex hull of its points) and its name at its median. Neighbouring groups take the most different colours of the palette, and one group can be drawn in the highlight colour.

Lets-plot primitive behind milia.plot.figures.clusters.scatter().

Parameters:
  • frame (DataFrame) – Data.

  • x (str) – x column.

  • y (str) – y column.

  • group (str) – Column naming the group of each point.

  • highlight (str | None) – Name of the group drawn in the highlight colour.

  • markers (bool) – Give each group its own marker shape.

  • numbers (bool) – Write the name of each group at its median.

  • outline (bool) – Draw the convex hull of each group in a pale tint.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> data = pd.DataFrame({"x": [0, 1, 0, 5, 6, 5], "y": [0, 0, 1, 5, 5, 6], "g": ["1"] * 3 + ["2"] * 3})
>>> bool(groups(data, "x", "y", "g").as_dict()["layers"])
True
milia.plot.lets.draw.strip(frame, x, y, color=None, hlines=(), title=None, xlabel=None, ylabel=None)#

Jittered strip of values per category.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Data.

  • x (str) – Category column.

  • y (str) – Value column.

  • color (str | None) – Column colouring points.

  • hlines (Sequence[float]) – y values of reference lines.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = strip(pd.DataFrame({"x": ["a", "a", "b"], "y": [1.0, 2.0, 3.0]}), "x", "y")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.hist(frame, x, fill=None, vlines=(), bins=30, title=None, xlabel=None, ylabel=None)#

Histogram, optionally split by a column.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Data.

  • x (str) – Value column.

  • fill (str | None) – Column splitting the histogram.

  • vlines (Sequence[float]) – x values of reference lines.

  • bins (int) – Number of bins.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label; count by default.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = hist(pd.DataFrame({"x": [0.1, 0.4, 0.5]}), "x", bins=3)
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.ranges(frame, y, x, low, high, title=None, xlabel=None, ylabel=None)#

Points with horizontal ranges, one row per item (e.g. ranks with intervals).

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Data, in display order.

  • y (str) – Column naming each row.

  • x (str) – Column of the point.

  • low (str) – Column of the range start.

  • high (str) – Column of the range end.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = ranges(pd.DataFrame({"n": ["a"], "r": [1], "lo": [1], "hi": [2]}), "n", "r", "lo", "hi")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.dumbbell(frame, y, start, end, title=None, xlabel=None, ylabel=None)#

Dumbbell chart: a start and end value per row, joined by a segment.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Data.

  • y (str) – Column naming each row.

  • start (str) – Column of the start value.

  • end (str) – Column of the end value.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = dumbbell(pd.DataFrame({"n": ["a"], "s": [0.9], "e": [0.2]}), "n", "s", "e")
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.band(frame, x, y, group, low, high, flagged=None, title=None, xlabel=None, ylabel=None)#

Per-entity traces over a shaded band, entities leaving it highlighted.

Lets-plot primitive behind the figures of milia.plot.figures.

Parameters:
  • frame (DataFrame) – Long-form traces.

  • x (str) – Step column.

  • y (str) – Value column.

  • group (str) – Entity column.

  • low (float) – Lower bound of the band.

  • high (float) – Upper bound of the band.

  • flagged (str | None) – Boolean column marking entities to highlight.

  • title (str | None) – Figure title.

  • xlabel (str | None) – x-axis label.

  • ylabel (str | None) – y-axis label.

Return type:

Any

Returns:

A lets-plot PlotSpec.

Examples

>>> import pandas as pd
>>> figure = band(pd.DataFrame({"s": [0, 1], "v": [1.0, 1.2], "g": ["a", "a"]}), "s", "v", "g", 0.9, 1.1)
>>> bool(figure.as_dict()["layers"])
True
milia.plot.lets.draw.accents()#

Accent colours of the current style, for figure code.

Return type:

dict[str, str]

Returns:

primary, danger and muted colours, as hex strings.

Examples

>>> sorted(accents())
['danger', 'muted', 'primary']