Skillversitas

Wedges and Arcs

Wedges and arcs draw angular shapes: pie slices, donut segments, gauges, and partial rings. Both glyphs are anchored at a point and swept between two angles.

Wedge Anatomy

A wedge is a filled sector defined by a center (x, y), a radius, a start and end angle, and an optional inner radius for donut shapes. All angles are in radians; a full circle is 2π:

import math
from bokeh.plotting import figure

p = figure(width=350, height=350)
p.wedge(x=[0], y=[0], radius=[0.9],
        start_angle=[0], end_angle=[math.pi / 2],
        fill_color="tomato", alpha=0.7)

Bokeh sweeps counterclockwise from start to end angle by default. Passing direction="clock" reverses the sweep.

Donut with Annular Wedge

annular_wedge adds an inner_radius, producing a ring sector — the standard building block of donut charts:

import math
from bokeh.palettes import Viridis5

cats = ["research", "design", "build", "test", "ship"]
vals = [30, 22, 18, 15, 15]
start = 0
p4 = figure(width=400, height=400, x_range=(-1.2, 1.2),
            y_range=(-1.2, 1.2))
for cat, val, color in zip(cats, vals, Viridis5):
    end = start + 2 * math.pi * val / 100
    p4.annular_wedge(x=[0], y=[0], inner_radius=[0.45],
                     outer_radius=[1.0],
                     start_angle=[start], end_angle=[end],
                     fill_color=color, line_color="white")
    start = end

Arcs

An arc is an open curve, not a fillable shape, so it takes only line properties — no fill_color:

import math
p.arc(x=[0, 1], y=[0, 1], radius=[0.5, 0.5],
      start_angle=[0, math.pi / 2],
      end_angle=[math.pi, math.pi + 1],
      line_width=5, line_color="navy")

Computing Angles from Data

Pie charts need cumulative angles, which you can derive with a running total. Avoid the walrus trick and keep it explicit:

import math

vals = [30, 22, 18, 15, 15]
total = sum(vals)
starts, ends = [], []
cur = 0
for v in vals:
    starts.append(cur)
    cur += 2 * math.pi * v / total
    ends.append(cur)

Keeping Proportions

Because pixels are not square units by default, circles and wedges can render as ellipses. Set equal axis ranges, constrain aspect, or use match_aspect=True on the figure so radial glyphs look round:

p = figure(title="Proportional", match_aspect=True,
           width=350, height=350)

Labels on Wedges

Compute a mid-angle to place a text glyph at the sector's centroid — a common pattern for slice labels:

mid = (start + end) / 2  # radians, per slice
lx = 0.75 * math.cos(mid)
ly = 0.75 * math.sin(mid)
p.text(x=[lx], y=[ly], text=[cat], text_align="center")

Summary

Wedge and annular_wedge draw filled sectors with optional ring holes while arc draws stroked curves; feed them radii in data units plus start/end angles in radians, derived from cumulative shares of a total, and set match_aspect so radial shapes stay circular.