supercontest.util.plotting
Utilities for graphing data.
Functions
Plots a horizontal bar chart of the given data. |
|
Plots a scatter chart of the given data. |
- supercontest.util.plotting.form_hbar(traces: defaultdict[int | float | str, defaultdict[int | float | str, int]], title: str, trace_order: tuple[int | float | str, ...], reverse: bool = True, colors: tuple[str, ...] | None = None, counts_to_perc: bool = True, agg: Callable[[Iterable[str | int | float]], int | float] | None = None) str
Plots a horizontal bar chart of the given data.
- Parameters:
traces –
{row: trace: count}. The keys are the rows (the y-axis values of the hbar), common across all traces. The values of the traces dict are dicts themselves, with a key for each trace (eg cover) and value for each count (eg 251 games covered). If there’s more than one trace, it will stack them (in order ofnames).title – Title of plot.
trace_order – For any plot, the rows must be sorted. This is the official “ranking” - the conclusion of the plot. It will sort by the values of the traces. Trace order is given by this arg, so the value of the first trace name will be the primary sort, then the second item will define the trace used to extract the values for secondary sort, and on and on.
reverse – Sorting the rows by trace values. By default, python sorts low to high. This function defaults to
True, sorting high to low.colors – Ordered colors of each trace (values).
counts_to_perc – By default, the innermost values are assumed to be counts and converted to per-row percentages (accross all traces). If
False, this leaves them as counts. If you’re only passing one trace, this will coerce toFalsesince the percentage will be 100 for all rows.agg – A function to aggregate the innermost values across all traces. This will flatten a stacked hbar of many traces into a single trace of the aggregated value (per row). This implicitly sets
counts_to_perc=False, since you’re reducing dimensionality to 1. Obviously the aggregation function must be compatible with the value types: mean() works for numbers, but not strings.
- Returns:
The json dump of the plot.
- supercontest.util.plotting.form_scatter(traces: tuple[dict[int | float, int | float], ...], title: str, names: tuple[str, ...], visibilities: tuple[bool, ...], pad_zero: bool = True, accumulate_y: bool = True) str
Plots a scatter chart of the given data.
- Parameters:
traces – Each element of the tuple is a trace, structured as a dict where the keys = xaxis and the vals = yaxis. This function only supports numerical data (for now), so it sorts according to those values (origin is 0/0, increasing along both axes).
title – Title of plot.
names – Ordered names of the traces (values).
visibilities – Ordered settings for the traces, True = show by default, False = legend.
pad_zero – Inject an x,y point of 0,0 at the beginning of each scatter’s trace.
accumulate_y – To accumulate yaxis values or not.
- Returns:
The json dump of the plot.