plotlet v0.6.2

bar

Categorical

["a","b","c","d"]

Minimal call

df = {"cat": ["a", "b", "c", "d"], "n": [4, 7, 3, 5]}

c = pt.chart(df, aes(x="cat", y="n", fill="cat"), ylabel="count",
             legend=False)
c.add_bar()

Worked example

["Thur","Fri","Sat","Sun"]
import plotlet as pt
from plotlet import aes

df = pt.load_dataset("tips")
days = ["Thur", "Fri", "Sat", "Sun"]
pct = {d: [] for d in days}
for bill, tip, day in zip(df["total_bill"], df["tip"], df["day"]):
    pct[day].append(100 * tip / bill)
rates = {"day": days, "rate": [sum(v) / len(v) for v in pct.values()]}

c = pt.chart(rates, aes(x="day", y="rate", fill="day"),
             title="mean tip rate by day", ylabel="tip (% of bill)",
             data_width=300, data_height=200)
c.add_bar(legend=False)

Docstring

Bar chart — long-form only.

  c.add_bar(aes(x="cat", y="val"))                                  # single
  c.add_bar(aes(x="cat", y="val"), fill="C0")                       # constant color
  c.add_bar(aes(x="cat", y="val", fill="series"), position="stack") # grouped
  c.add_bar(aes(x="cat", y="val", fill="series"), position="dodge")
  c.add_bar(aes(x="cat", y="val", fill="series"), position="fill")  # 100% stack
  c.add_bar(aes(x="cat", y="mean", fill="series", yerr="sd"))       # mean±err
  c.add_bar(aes(x="cat"), stat="count")                             # countplot
  c.add_bar(aes(x="cat", y="raw"), stat="mean")                     # mean±CI

`position` defaults to `"stack"` whenever `aes(fill=...)` maps a column
with more than one unique value — except with `yerr=`/`xerr=` or `stat="mean"`,
which default to `"dodge"` (error bars aren't defined for stacked bars,
and stacked means are misleading). Duplicate (cat, group) rows are
summed; with error bars they raise instead, since offsets don't
aggregate the way sums do.

Stats (seaborn countplot / barplot, ggplot geom_bar):
  stat='identity'     y values used as given (duplicates summed)
  stat='count'        bar height = number of rows per category; drop y=
  stat='mean'         bar height = mean of y per category, with a CI
                      error bar: ci='t' (default), 'boot', or None;
                      level=0.95, n_boot=1000, seed=0 as in pointplot

Aesthetics:
  fill=         bare → literal color; aes(fill="col") → grouped multi-series
  color=        stroke color (constant, default None = no stroke)
  palette=      maps group levels → colors when fill is mapped in aes

Error bars (same specs as the errorbar artist — aes-mapped column, bare
scalar, or a (lower, upper) tuple of either):
  yerr=         value-axis error for vertical bars
  xerr=         value-axis error for horizontal bars (orientation='h')
  ecolor=<themed>     whisker color
  capsize=<themed>    whisker cap width (px)

Other styling kwargs:
  orientation='v'     'h' for horizontal bars
  bottom=0            baseline value (single / dodge); stacks always start at 0
  alpha=<themed>      bar fill opacity
  linewidth=<themed>  stroke width (used only when color is set)
  width=0.8           dodged-group total width as a band fraction
  gap=0.1             slot-gap fraction between dodged bars
  label=None          legend label (overridden by column-driven grouping)