Feynman Diagram for Particle Interactions in Makie.jl (Julia)

The same plot in 14 other libraries — Python: Altair, Bokeh, lets-plot, Matplotlib, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts, MUI X Charts. Compare all 15 side by side: Feynman Diagram for Particle Interactions in Python, R, Julia and JavaScript.

A Feynman diagram visualizes interactions between subatomic particles in quantum field theory. Different line styles represent different particle types: straight lines for fermions (electrons, quarks), wavy lines for photons, curly/looped lines for gluons, and dashed lines for scalar bosons (e.g., Higgs). Lines meet at vertices representing interaction points. Invented by Richard Feynman, these diagrams are both a computational tool and a cultural icon of modern physics.

Feynman Diagram for Particle Interactions rendered with Makie.jl

Renders

Julia source (Makie.jl)

# anyplot.ai
# feynman-basic: Feynman Diagram for Particle Interactions
# Library: makie 0.24.16 | Julia 1.13.4
# Quality: 86/100 | Updated: 2026-12-01

using CairoMakie
using Colors


const THEME     = get(ENV, "ANYPLOT_THEME", "light")
const PAGE_BG   = THEME == "light" ? colorant"#FAF8F1" : colorant"#1A1A17"
const INK       = THEME == "light" ? colorant"#1A1A17" : colorant"#F0EFE8"
const INK_SOFT  = THEME == "light" ? colorant"#4A4A44" : colorant"#B8B7B0"
const INK_MUTED = THEME == "light" ? colorant"#6B6A63" : colorant"#A8A79F"

const FERMION_COLOR = colorant"#009E73"  # brand green  (e-, e+, μ-, μ+, quarks)
const GLUON_COLOR   = colorant"#C475FD"  # lavender     (gluons / QCD)
const PHOTON_COLOR  = colorant"#4467A3"  # blue         (photons / EM bosons)
const SCALAR_COLOR  = colorant"#BD8233"  # ochre        (scalar bosons / Higgs)

# ─── Makie @recipe: composable Feynman propagator plot types ─────────────────
# Each recipe becomes a reusable, composable CairoMakie primitive — a Makie-
# exclusive feature that makes the diagram grammar extensible and domain-specific.

# Filled triangle centred on (x, y) pointing along the unit vector (ux, uy)
function arrowhead(x, y, ux, uy, size)
    nx, ny = -uy, ux
    [Point2f(x + ux * size * 0.6, y + uy * size * 0.6),
     Point2f(x - ux * size * 0.4 + nx * size * 0.4, y - uy * size * 0.4 + ny * size * 0.4),
     Point2f(x - ux * size * 0.4 - nx * size * 0.4, y - uy * size * 0.4 - ny * size * 0.4)]
end

# Fermion propagator: solid line with a midpoint direction arrow
@recipe(FermionProp, xs, ys, direction) do scene
    Attributes(
        color     = FERMION_COLOR,
        linewidth = 2.5,
        arrowsize = 0.32,
    )
end

function Makie.plot!(fp::FermionProp)
    xs        = fp[1][]
    ys        = fp[2][]
    direction = fp[3][]   # 1 = particle (forward), -1 = antiparticle (backward)
    clr       = fp.color[]
    lw        = fp.linewidth[]

    lines!(fp, xs, ys; color = clr, linewidth = lw)

    n   = length(xs)
    mid = n ÷ 2
    dx  = xs[min(mid + 1, n)] - xs[max(mid - 1, 1)]
    dy  = ys[min(mid + 1, n)] - ys[max(mid - 1, 1)]
    len = sqrt(dx^2 + dy^2)
    if len > 1e-9
        poly!(fp, arrowhead(xs[mid], ys[mid], direction * dx / len, direction * dy / len, fp.arrowsize[]);
              color = clr)
    end
    fp
end

# Photon propagator: transverse sinusoidal wave
@recipe(PhotonProp, x1, y1, x2, y2) do scene
    Attributes(
        color     = PHOTON_COLOR,
        linewidth = 2.5,
        n_waves   = 9,
        amplitude = 0.038,
    )
end

function Makie.plot!(pp::PhotonProp)
    x1, y1 = pp[1][], pp[2][]
    x2, y2 = pp[3][], pp[4][]
    clr     = pp.color[]
    lw      = pp.linewidth[]
    nw      = pp.n_waves[]
    amp     = pp.amplitude[]

    dx  = x2 - x1; dy = y2 - y1
    len = sqrt(dx^2 + dy^2)
    nx  = -dy / len; ny = dx / len   # unit normal (transverse direction)

    t    = LinRange(0.0, 1.0, 600)
    xs_w = @. x1 + t * dx + amp * sin(nw * 2π * t) * nx
    ys_w = @. y1 + t * dy + amp * sin(nw * 2π * t) * ny
    lines!(pp, xs_w, ys_w; color = clr, linewidth = lw)
    pp
end

# Gluon propagator: one-sided curly bumps via |sin| — visually distinct from photon
@recipe(GluonProp, x1, y1, x2, y2) do scene
    Attributes(
        color     = GLUON_COLOR,
        linewidth = 2.5,
        n_loops   = 7,
        amplitude = 0.048,
    )
end

function Makie.plot!(gp::GluonProp)
    x1, y1 = gp[1][], gp[2][]
    x2, y2 = gp[3][], gp[4][]
    clr     = gp.color[]
    lw      = gp.linewidth[]
    nl      = gp.n_loops[]
    amp     = gp.amplitude[]

    dx  = x2 - x1; dy = y2 - y1
    len = sqrt(dx^2 + dy^2)
    nx  = -dy / len; ny = dx / len

    # Trochoid along the line: the forward position swings back each turn, so the curve
    # crosses itself and draws a looped coil; both ends land exactly on the line.
    pitch = len / nl
    t     = LinRange(0.0, 1.0, 800)
    phase = @. nl * 2π * t
    along = @. t * len - 0.26 * pitch * sin(phase)
    side  = @. amp * (1 - cos(phase)) / 2
    xs_c  = @. x1 + along * dx / len + side * nx
    ys_c  = @. y1 + along * dy / len + side * ny
    lines!(gp, xs_c, ys_c; color = clr, linewidth = lw)
    gp
end

# Scalar boson propagator: dashed line (Higgs, etc.)
@recipe(ScalarProp, x1, y1, x2, y2) do scene
    Attributes(
        color     = SCALAR_COLOR,
        linewidth = 2.5,
    )
end

function Makie.plot!(sp::ScalarProp)
    x1, y1 = sp[1][], sp[2][]
    x2, y2 = sp[3][], sp[4][]
    lines!(sp, [x1, x2], [y1, y2]; color = sp.color[], linewidth = sp.linewidth[], linestyle = :dash)
    sp
end

# ─── Data: gg → H → γγ (all four line types in one diagram) ─────────────────
# Schematic layout in a 16 x 9 box; only which lines meet at which vertex matters.
vertices = Dict(
    "A" => (4.2, 6.0), "B" => (4.2, 3.0), "C" => (6.4, 4.5),    # top-quark triangle 1
    "D" => (9.6, 4.5), "E" => (11.8, 6.0), "F" => (11.8, 3.0),  # top-quark triangle 2
)
g1_in, g2_in   = (0.8, 7.4), (0.8, 1.6)    # incoming gluons
p1_out, p2_out = (15.2, 7.4), (15.2, 1.6)  # outgoing photons

# Top-quark loop: arrows run around each triangle in one direction (clockwise)
loops = [("A", "C"), ("C", "B"), ("B", "A"), ("D", "E"), ("E", "F"), ("F", "D")]

# ─── Plot ────────────────────────────────────────────────────────────────────
fig = Figure(
    size            = (1600, 900),
    fontsize        = 14,
    backgroundcolor = PAGE_BG,
)

Label(fig[0, 1], "feynman-basic · julia · makie · anyplot.ai";
      fontsize = 20, color = INK, halign = :center)

ax = Axis(fig[1, 1];
    backgroundcolor    = PAGE_BG,
    topspinevisible    = false,
    rightspinevisible  = false,
    leftspinevisible   = false,
    bottomspinevisible = false,
    xgridvisible       = false,
    ygridvisible       = false,
    xticksvisible      = false,
    yticksvisible      = false,
    xticklabelsvisible = false,
    yticklabelsvisible = false,
)
xlims!(ax, 0.0, 16.0)
ylims!(ax, 0.0, 9.0)

n_pts = 100
for (a, b) in loops
    (xa, ya), (xb, yb) = vertices[a], vertices[b]
    fermionprop!(ax, LinRange(xa, xb, n_pts), LinRange(ya, yb, n_pts), 1)
end

gluonprop!(ax, g1_in..., vertices["A"]...; n_loops = 7, amplitude = 0.4)
gluonprop!(ax, g2_in..., vertices["B"]...; n_loops = 7, amplitude = 0.4)
scalarprop!(ax, vertices["C"]..., vertices["D"]...)
photonprop!(ax, vertices["E"]..., p1_out...; n_waves = 5, amplitude = 0.2)
photonprop!(ax, vertices["F"]..., p2_out...; n_waves = 5, amplitude = 0.2)

vx = [v[1] for v in values(vertices)]
vy = [v[2] for v in values(vertices)]
scatter!(ax, vx, vy; color = INK, markersize = 14, strokewidth = 0)

text!(ax, 2.3, 7.35; text = "g", fontsize = 30, color = GLUON_COLOR, align = (:center, :bottom))
text!(ax, 2.3, 1.75; text = "g", fontsize = 30, color = GLUON_COLOR, align = (:center, :top))
text!(ax, 8.0, 4.85; text = "H", fontsize = 30, color = SCALAR_COLOR, align = (:center, :bottom))
text!(ax, 13.4, 7.4; text = "γ", fontsize = 30, color = PHOTON_COLOR, align = (:center, :bottom))
text!(ax, 13.4, 1.7; text = "γ", fontsize = 30, color = PHOTON_COLOR, align = (:center, :top))
for (x, y, al) in [(5.65, 5.6, (:left, :bottom)), (5.65, 3.4, (:left, :top)), (3.95, 4.5, (:right, :center)),
                   (10.35, 5.6, (:right, :bottom)), (10.35, 3.4, (:right, :top)), (12.05, 4.5, (:left, :center))]
    text!(ax, x, y; text = "t", fontsize = 28, color = FERMION_COLOR, align = al)
end

# Time axis
lines!(ax, [0.5, 2.0], [0.6, 0.6]; color = INK_MUTED, linewidth = 1.5)
poly!(ax, arrowhead(2.0, 0.6, 1.0, 0.0, 0.3); color = INK_MUTED)
text!(ax, 2.35, 0.6; text = "time", fontsize = 20, color = INK_MUTED, align = (:left, :center))

# Line-style key
key_x = [4.6, 7.4, 10.2, 13.0]
key_names = ["Fermion", "Photon", "Gluon", "Scalar"]
key_colors = [FERMION_COLOR, PHOTON_COLOR, GLUON_COLOR, SCALAR_COLOR]
ky = 0.6
fermionprop!(ax, LinRange(key_x[1], key_x[1] + 1.0, n_pts), fill(ky, n_pts), 1; arrowsize = 0.32)
photonprop!(ax, key_x[2], ky, key_x[2] + 1.0, ky; n_waves = 3, amplitude = 0.12)
gluonprop!(ax, key_x[3], ky, key_x[3] + 1.0, ky; n_loops = 4, amplitude = 0.2)
scalarprop!(ax, key_x[4], ky, key_x[4] + 1.0, ky)
for (x, name, clr) in zip(key_x, key_names, key_colors)
    text!(ax, x + 1.2, ky; text = name, fontsize = 20, color = clr, align = (:left, :center))
end

colsize!(fig.layout, 1, Relative(1))

save("plot-$(THEME).png", fig; px_per_unit = 2)

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/feynman-basic/makie/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": "feynman-basic",
  "language": "julia",
  "library": "makie",
  "page": "https://anyplot.ai/feynman-basic/julia/makie",
  "hub": "https://anyplot.ai/feynman-basic",
  "code_json": "https://api.anyplot.ai/specs/feynman-basic/makie/code",
  "spec_json": "https://api.anyplot.ai/specs/feynman-basic",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/feynman-basic/julia/makie/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/feynman-basic/julia/makie/plot-dark.png",
  "quality_score": 86.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Feynman Diagram for Particle Interactions on anyplot.ai.

Other implementations