The same plot in 14 other libraries — Python: Altair, Bokeh, Matplotlib, 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: Parliament Seat Chart in Python, R, Julia and JavaScript.
A semicircular parliament seat chart visualizes political party representation by arranging seats in concentric arcs. Each seat is displayed as an individual dot or segment, colored by party affiliation. This visualization is ideal for showing the composition of legislative bodies, election results, and voting bloc distributions at a glance.

""" anyplot.ai
parliament-basic: Parliament Seat Chart
Library: letsplot 4.11.0 | Python 3.14.10
Quality: 85/100 | Updated: 2026-12-05
"""
import os
import re
import numpy as np
import pandas as pd
from lets_plot import (
LetsPlot,
aes,
coord_fixed,
element_rect,
element_text,
geom_point,
geom_segment,
geom_text,
gggrid,
ggplot,
ggsave,
ggsize,
labs,
scale_color_manual,
scale_y_continuous,
theme,
theme_void,
)
LetsPlot.setup_html()
# Theme tokens
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"
# Imprint palette: all eight positions, one per party in order
IMPRINT_PALETTE = ["#009E73", "#C475FD", "#4467A3", "#BD8233", "#AE3030", "#2ABCCD", "#954477", "#99B314"]
# Constants
N_ROWS = 8 # concentric arcs of the chamber
INNER_RADIUS = 0.45
ROW_GAP = 0.075
# Columns: set these to your table's column names
PARTY = "Party" # role: party
SEATS = "Seats" # role: seats
COLOR = "Color" # role: color
# Data: replace this block with your own table, for example df = pd.read_csv("chamber.csv")
df = pd.DataFrame(
{
PARTY: [
"Riverbank Alliance",
"Weavers' Union",
"Harbor League",
"Quarry Collective",
"Orchard Guild",
"Lantern Assembly",
],
SEATS: [85, 72, 58, 35, 95, 55],
COLOR: ["#009E73", "#C475FD", "#4467A3", "#BD8233", "#AE3030", "#2ABCCD"],
}
)
# Plot
total = int(df[SEATS].astype(int).sum())
majority = total // 2 + 1
# Rows hold seats in proportion to their radius, so seat spacing is even
radii = INNER_RADIUS + ROW_GAP * np.arange(N_ROWS)
per_row = np.floor(radii / radii.sum() * total).astype(int)
per_row[-1] += total - per_row.sum()
angle = np.concatenate([np.linspace(np.pi, 0, n) for n in per_row])
radius = np.concatenate([np.full(n, r) for n, r in zip(per_row, radii, strict=True)])
# Sweep the seats from left to right and hand them out party by party
order = np.lexsort((radius, -angle))
angle, radius = angle[order], radius[order]
labels = [f"{p} ({int(s)})" for p, s in zip(df[PARTY], df[SEATS], strict=True)]
seat_party = np.repeat(labels, df[SEATS].astype(int))
seats = pd.DataFrame(
{"x": radius * np.cos(angle), "y": radius * np.sin(angle), "label": pd.Categorical(seat_party, categories=labels)}
)
# A party's own hex color wins; anything else, or a table without the optional color column,
# falls back to the Imprint palette in order
own_colors = df[COLOR].tolist() if COLOR in df.columns else [None] * len(df)
seat_colors = [
c if re.fullmatch(r"#[0-9A-Fa-f]{6}", str(c)) else IMPRINT_PALETTE[i % len(IMPRINT_PALETTE)]
for i, c in enumerate(own_colors)
]
# Majority threshold: a radial line between the last seat of the majority and the next one,
# drawn in the gaps inside and outside the seat arcs so it never covers a seat
cut = (angle[majority - 1] + angle[majority]) / 2
r_in, r_out = radii[0] - 0.09, radii[-1] + 0.09
r_label = r_out + 0.17
threshold = pd.DataFrame(
{
"x": [r_in * np.cos(cut), r_out * np.cos(cut)],
"y": [r_in * np.sin(cut), r_out * np.sin(cut)],
"xend": [(r_in - 0.1) * np.cos(cut), (r_out + 0.07) * np.cos(cut)],
"yend": [(r_in - 0.1) * np.sin(cut), (r_out + 0.07) * np.sin(cut)],
}
)
threshold_label = pd.DataFrame(
{"x": [r_label * np.cos(cut)], "y": [r_label * np.sin(cut)], "text": [f"Majority: {majority} of {total}"]}
)
anyplot_theme = theme(
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
plot_title=element_text(color=INK, size=16, hjust=0.5),
legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),
legend_text=element_text(color=INK_SOFT, size=11),
legend_title=element_text(color=INK, size=12),
plot_margin=[24, 30, 0, 30],
)
plot = (
ggplot()
+ geom_point(aes(x="x", y="y", color="label"), data=seats, size=3.2)
+ geom_segment(aes(x="x", y="y", xend="xend", yend="yend"), data=threshold, color=INK, size=0.8)
+ geom_text(aes(x="x", y="y", label="text"), data=threshold_label, color=INK_SOFT, size=5)
+ scale_color_manual(values=seat_colors, breaks=labels)
+ scale_y_continuous(expand=[0.105, 0])
+ coord_fixed()
+ theme_void()
+ anyplot_theme
+ labs(title="parliament-basic · python · letsplot · anyplot.ai", color=f"{PARTY} (seats)")
)
# coord_fixed narrows the plot box; a one-panel grid paints the whole canvas in the page color
plot = gggrid([plot]) + ggsize(800, 450) + theme(plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG))
# Save as PNG and HTML with theme suffix
ggsave(plot, f"plot-{THEME}.png", path=".", scale=4)
ggsave(plot, f"plot-{THEME}.html", path=".")
Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/parliament-basic/letsplot/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": "parliament-basic",
"language": "python",
"library": "letsplot",
"page": "https://anyplot.ai/parliament-basic/python/letsplot",
"hub": "https://anyplot.ai/parliament-basic",
"code_json": "https://api.anyplot.ai/specs/parliament-basic/letsplot/code",
"spec_json": "https://api.anyplot.ai/specs/parliament-basic",
"render_light_png": "https://storage.googleapis.com/anyplot-images/plots/parliament-basic/python/letsplot/plot-light.png",
"render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/parliament-basic/python/letsplot/plot-dark.png",
"interactive_light_html": "https://storage.googleapis.com/anyplot-images/plots/parliament-basic/python/letsplot/plot-light.html",
"interactive_dark_html": "https://storage.googleapis.com/anyplot-images/plots/parliament-basic/python/letsplot/plot-dark.html",
"quality_score": 85.0,
"license": "MIT",
"guide": "https://anyplot.ai/llms.txt"
}Part of Parliament Seat Chart on anyplot.ai.