Chris Parmer — home

Radiation pattern

Antenna Engineering — 8-element ULA, broadside

Example from the compendium of canonical charts

Antenna Engineering — Radiation pattern (8-element ULA, broadside)

Python Code

"""Antenna Engineering — Radiation pattern (8-element ULA, broadside)."""
from pathlib import Path

# ── Palette + theme (matching the Plotly Studio gallery these charts ship in) ──
VIOLET, TEAL, GREEN, PINK, ORANGE = "#845EEE", "#52B3D0", "#55B685", "#DA5597", "#E9A23B"
PRIMARY, SECONDARY = VIOLET, TEAL
COLORWAY = [VIOLET, TEAL, GREEN, PINK, ORANGE]
BG, TEXT, GRID, MUTED = "#ffffff", "#1c2024", "#d9d9e0", "#60646c"
FONT = "Inter, -apple-system, BlinkMacSystemFont, sans-serif"
COLORSCALE = [[0, "rgba(132, 94, 238, 0.05)"], [1, "rgba(132, 94, 238, 0.9)"]]


def apply_theme(fig):
    """Light gallery theme: white background, Inter font, soft gridlines."""
    fig.update_layout(
        paper_bgcolor=BG, plot_bgcolor=BG, colorway=COLORWAY,
        font=dict(family=FONT, color=TEXT, size=12),
        legend=dict(font=dict(color=TEXT)),
        hoverlabel=dict(bgcolor="#f0f0f3", font=dict(color=TEXT, family=FONT), bordercolor=GRID),
    )
    fig.update_xaxes(gridcolor=GRID, linecolor=GRID, zerolinecolor=GRID)
    fig.update_yaxes(gridcolor=GRID, linecolor=GRID, zerolinecolor=GRID)


def fetch_csv(url, **kwargs):
    import io
    import pandas as pd
    import requests
    r = requests.get(url, timeout=60)
    r.raise_for_status()
    return pd.read_csv(io.StringIO(r.text), **kwargs)


def fetch_json(url):
    import requests
    r = requests.get(url, timeout=60)
    r.raise_for_status()
    return r.json()

import numpy as np
import plotly.graph_objects as go


def generate():
    N = 8          # elements
    d = 0.5        # spacing in wavelengths
    beta = 0.0     # progressive phase shift (broadside)

    theta = np.linspace(0, 2 * np.pi, 3600)

    # Phase difference per element
    psi = 2 * np.pi * d * np.cos(theta) + beta

    # Array factor: use sinc-like formula; handle ψ→0
    # AF = sin(N*ψ/2) / sin(ψ/2)
    half_psi = psi / 2
    with np.errstate(divide="ignore", invalid="ignore"):
        AF = np.where(
            np.abs(np.sin(half_psi)) < 1e-10,
            float(N),
            np.abs(np.sin(N * half_psi) / np.sin(half_psi)),
        )

    AF_norm = AF / N   # normalize main lobe to 1.0

    # Convert to dB and clip at -40 dB
    AF_dB = 20 * np.log10(AF_norm + 1e-10)
    AF_dB = np.maximum(AF_dB, -40.0)

    # Shift to positive for scatterpolar (add 40)
    r_vals = AF_dB + 40  # range [0, 40]

    fig = go.Figure()

    fig.add_trace(go.Scatterpolar(
        r=r_vals,
        theta=np.degrees(theta),
        mode="lines",
        name="Array factor",
        line=dict(color=VIOLET, width=2),
        hovertemplate="θ=%{theta:.1f}°, %{r:.1f}−40 dB<extra></extra>",
    ))

    fig.update_layout(
        polar=dict(
            radialaxis=dict(
                range=[0, 42],
                tickvals=[0, 10, 20, 30, 40],
                ticktext=["−40", "−30", "−20", "−10", "0"],
                title="dB",
            ),
            angularaxis=dict(direction="clockwise", rotation=90),
        ),
        legend=dict(orientation="h", y=1.06),
        margin=dict(t=60, b=60, l=60, r=60),
        height=560,
    )
    apply_theme(fig)
    return fig


fig = generate()
fig.show()

Made with Plotly