Pictogram Chart (Isotype Visualization) in Matplotlib (Python)

The same plot in 14 other libraries — Python: Altair, Bokeh, lets-plot, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; Julia: Makie.jl; JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts, MUI X Charts. Compare all 15 side by side: Pictogram Chart (Isotype Visualization) in Python, R, Julia and JavaScript.

A pictogram chart represents quantities using repeated icons or symbols, where each icon stands for a fixed number of units. Inspired by Otto Neurath's ISOTYPE system, this visualization makes numerical comparisons more intuitive and engaging than plain bar charts. It is especially effective for public-facing data communication and infographics where visual appeal and immediate comprehension are important.

Pictogram Chart (Isotype Visualization) rendered with Matplotlib

Renders

Python source (Matplotlib)

""" anyplot.ai
pictogram-basic: Pictogram Chart (Isotype Visualization)
Library: matplotlib 3.11.2 | Python 3.14.10
Quality: 84/100 | Updated: 2026-11-30
"""

import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.lines import Line2D
from matplotlib.patches import Circle, Rectangle


# Theme tokens — Imprint palette chrome
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"

# Imprint palette — position 1 (brand green) is the single series
IMPRINT_PALETTE = ["#009E73", "#C475FD", "#4467A3", "#BD8233", "#AE3030", "#2ABCCD", "#954477", "#99B314"]
BRAND = IMPRINT_PALETTE[0]

# Constants
MAX_ROW_ICONS = 8  # the longest row holds about this many icons

# Columns: set these to your table's column names
FRUIT = "Fruit"  # role: category
PRODUCTION = "Production (Mt)"  # role: value

# Data: replace this block with your own table, for example df = pd.read_csv("production.csv")
df = pd.DataFrame({FRUIT: ["Apples", "Oranges", "Bananas", "Grapes", "Mangoes"], PRODUCTION: [93, 76, 135, 79, 58]})

# Plot
df = df.dropna(subset=[PRODUCTION])
categories = df[FRUIT].tolist()
values = df[PRODUCTION].astype(float).tolist()
# One icon = a round unit (1, 2 or 5 times a power of ten) that fits the largest value in about MAX_ROW_ICONS icons
raw_unit = max(values) / MAX_ROW_ICONS
magnitude = 10 ** np.floor(np.log10(raw_unit))
ICON_UNIT = max(m * magnitude for m in (1, 2, 5, 10) if m * magnitude <= raw_unit * 1.0001)
n_cats = len(categories)
full_icons = [int(v // ICON_UNIT) for v in values]
partials = [(v % ICON_UNIT) / ICON_UNIT for v in values]
max_icons = max(full_icons) + 1  # longest row incl. its partial icon

# Layout parameters
icon_r = 0.33  # icon radius in data units
x_step = 0.88  # center-to-center horizontal spacing
ROW_GAP = 1.6  # vertical spacing between rows, so the rows fill the equal-aspect canvas
y_rows = [ROW_GAP * i for i in range(n_cats - 1, -1, -1)]  # top → bottom

# Figure
fig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)
ax.set_facecolor(PAGE_BG)

# Draw icons row by row
for row_idx, (n_full, frac) in enumerate(zip(full_icons, partials, strict=True)):
    y = y_rows[row_idx]

    # Full filled icons
    for i in range(n_full):
        ax.add_patch(
            Circle((i * x_step, y), icon_r, facecolor=BRAND, edgecolor="none", transform=ax.transData, zorder=3)
        )

    # Partial icon: muted background + left-filled arc polygon
    if frac > 0:
        x_p = n_full * x_step
        ax.add_patch(
            Circle(
                (x_p, y), icon_r, facecolor=INK_MUTED, alpha=0.25, edgecolor="none", transform=ax.transData, zorder=2
            )
        )
        # Brand circle clipped to its left `frac` share
        filled = Circle((x_p, y), icon_r, facecolor=BRAND, edgecolor="none", zorder=3)
        ax.add_patch(filled)
        filled.set_clip_path(
            Rectangle((x_p - icon_r, y - icon_r), 2 * icon_r * frac, 2 * icon_r, transform=ax.transData)
        )

    # Value annotation at row end
    x_end = (n_full + (1 if frac > 0 else 0)) * x_step + icon_r + 0.20
    ax.text(x_end, y, f"{values[row_idx]:g} Mt", fontsize=9, color=INK_SOFT, va="center", ha="left")

# Axes bounds
ax.set_xlim(-icon_r * 2.2, (max_icons - 1) * x_step + icon_r + 1.9)
ax.set_ylim(-0.9 * ROW_GAP, (n_cats - 1) * ROW_GAP + 0.9 * ROW_GAP)
ax.set_aspect("equal", adjustable="datalim")  # keep icons circular whatever the row length

# Category labels on left axis
ax.set_yticks(y_rows)
ax.set_yticklabels(categories, fontsize=10, color=INK_SOFT)
ax.tick_params(axis="y", length=0, labelcolor=INK_SOFT)
ax.set_xticks([])

# Spine styling — L-frame (left + bottom) for row anchoring
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["bottom"].set_color(INK_SOFT)
ax.spines["bottom"].set_linewidth(0.5)
ax.spines["left"].set_color(INK_SOFT)
ax.spines["left"].set_linewidth(0.5)

# Title
title = "Estimated Global Fruit Production · pictogram-basic · python · matplotlib · anyplot.ai"
n_t = len(title)
title_fs = max(8, round(12 * 67 / n_t)) if n_t > 67 else 12
ax.set_title(title, fontsize=title_fs, fontweight="medium", color=INK, pad=12)

# Legend: unit key
leg = ax.legend(
    handles=[
        Line2D(
            [],
            [],
            marker="o",
            linestyle="none",
            markersize=9,
            markerfacecolor=BRAND,
            markeredgecolor="none",
            label=f"= {ICON_UNIT:g} million tonnes",
        )
    ],
    fontsize=8,
    loc="lower right",
    facecolor=ELEVATED_BG,
    edgecolor=INK_SOFT,
    framealpha=0.9,
)
leg.get_frame().set_linewidth(0.5)
plt.setp(leg.get_texts(), color=INK_SOFT)

fig.subplots_adjust(left=0.13, right=0.97, top=0.91, bottom=0.06)

plt.savefig(f"plot-{THEME}.png", dpi=400, facecolor=PAGE_BG)
plt.close()

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/pictogram-basic/matplotlib/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "pictogram-basic",
  "language": "python",
  "library": "matplotlib",
  "page": "https://anyplot.ai/pictogram-basic/python/matplotlib",
  "hub": "https://anyplot.ai/pictogram-basic",
  "code_json": "https://api.anyplot.ai/specs/pictogram-basic/matplotlib/code",
  "spec_json": "https://api.anyplot.ai/specs/pictogram-basic",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/pictogram-basic/python/matplotlib/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/pictogram-basic/python/matplotlib/plot-dark.png",
  "quality_score": 84.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Pictogram Chart (Isotype Visualization) on anyplot.ai.

Other implementations