Skip to content
svgbrushablebar

Bar chart

How often does each category occur?

Demo data · seed 20261101 · 2,000 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Compare bar lengths: they all start at zero, so length is the value.
  2. Read from the longest down for the ranking.
  3. Check whether an “Other” bar groups levels beyond the top ones.
  1. Callout 1: Bar length: the count or share.
  2. Callout 2: The small categories together may still matter.

Watch out

  • Never cut the y axis on a bar chart: bars encode length, so a truncated axis exaggerates differences.

Defaults

Value
Count
Show counts or shares.
Also: Percent
Orientation
Columns
Draw bars vertically or horizontally; horizontal suits long labels.
Also: Bars
Order
By frequency
How rows or groups are ordered.
Also: Alphabetical
Top levels
12
How many levels to show; the rest are grouped into Other.
Range 3 to 30, step 1
Colour
Single
How bars or lines are coloured.
Also: By level
Value labels
On
Print each value on the chart.

Pinned in the code

  • Levels sorted by descending count (ties alphabetical) unless an order is declared in the data dictionary.
  • Levels beyond the top k are pooled into “Other” (drawn in neutral grey); missing values are excluded and reported separately.
  • Percent = count / non-missing rows.
# Bar chart — Codesplash Chart Lab (recipe "bar")
# controls: value=count, orientation=vertical, order=freq, top=12, color=single, labels=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("bar-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

counts = df["channel"].dropna().astype(str).value_counts()  # missing values excluded
counts = counts.sort_values(ascending=False, kind="stable")  # by frequency
if len(counts) > 12:  # pool levels beyond the top 12 into "Other"
    top = counts.sort_values(ascending=False).iloc[:12]
    counts = pd.concat([counts[counts.index.isin(top.index)], pd.Series({"Other": counts.drop(top.index).sum()})])
values = counts
colors = [PALETTE[0] if k != "Other" else "#9aa0a6" for k in values.index]

fig, ax = plt.subplots(figsize=(7, 4))
bars = ax.bar(values.index, values.values, color=colors)
ax.bar_label(bars, fmt="%d", padding=2, fontsize=8)
ax.set_ylabel("Count")
ax.tick_params(axis="x", labelrotation=30)
ax.set_xlabel("channel")
plt.show()

Needs pandas, numpy, matplotlib · reads bar-demo.csv · app theme from the optional codesplash helper