Pole-zero plot
Control Systems — s-plane closed-loop + z-plane Butterworth
Example from the compendium of canonical charts
Python Code
"""Control Systems — Pole-zero plot (s-plane closed-loop + z-plane Butterworth)."""
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
from plotly.subplots import make_subplots
from scipy.signal import tf2zpk, butter
def generate():
# s-plane: closed-loop at K=6: num=6, den=s^3+3s^2+2s+6
z_s, p_s, k_s = tf2zpk([6], [1, 3, 2, 6])
# z-plane: 2nd-order Butterworth, Wn=0.3 (digital)
b, a = butter(2, 0.3)
z_z, p_z, k_z = tf2zpk(b, a)
fig = make_subplots(
rows=1, cols=2,
subplot_titles=["s-plane (Closed-loop K=6)", "z-plane (Butterworth, Wn=0.3)"],
horizontal_spacing=0.12,
)
# ── s-plane ──────────────────────────────────────────────────────────────
# Stability boundary: vertical line at Re=0
fig.add_shape(
type="line", x0=0, y0=-3, x1=0, y1=3,
line=dict(color=GRID, width=1, dash="dash"),
row=1, col=1,
)
# Poles
fig.add_trace(go.Scatter(
x=p_s.real, y=p_s.imag,
mode="markers",
name="Poles (s)",
marker=dict(color=VIOLET, size=12, symbol="x", line=dict(width=2.5)),
hovertemplate="s=(%{x:.3f}+j%{y:.3f})<extra>pole</extra>",
), row=1, col=1)
# Zeros
if len(z_s) > 0:
fig.add_trace(go.Scatter(
x=z_s.real, y=z_s.imag,
mode="markers",
name="Zeros (s)",
marker=dict(color=PINK, size=12, symbol="circle-open", line=dict(width=2.5)),
hovertemplate="s=(%{x:.3f}+j%{y:.3f})<extra>zero</extra>",
), row=1, col=1)
# ── z-plane ──────────────────────────────────────────────────────────────
# Unit circle
theta_uc = np.linspace(0, 2 * np.pi, 360)
fig.add_trace(go.Scatter(
x=np.cos(theta_uc), y=np.sin(theta_uc),
mode="lines",
name="Unit circle",
line=dict(color=GRID, width=1, dash="dash"),
showlegend=True,
hoverinfo="skip",
), row=1, col=2)
# Poles
fig.add_trace(go.Scatter(
x=p_z.real, y=p_z.imag,
mode="markers",
name="Poles (z)",
marker=dict(color=TEAL, size=12, symbol="x", line=dict(width=2.5)),
hovertemplate="z=(%{x:.3f}+j%{y:.3f})<extra>pole</extra>",
), row=1, col=2)
# Zeros
fig.add_trace(go.Scatter(
x=z_z.real, y=z_z.imag,
mode="markers",
name="Zeros (z)",
marker=dict(color=PINK, size=12, symbol="circle-open", line=dict(width=2.5)),
hovertemplate="z=(%{x:.3f}+j%{y:.3f})<extra>zero</extra>",
), row=1, col=2)
fig.update_layout(
legend=dict(orientation="h", y=1.12),
margin=dict(t=60, b=60, l=60, r=40),
height=520,
)
# Equal aspect for both subplots
fig.update_xaxes(
zeroline=True, zerolinecolor=GRID, zerolinewidth=1,
title_text="Real",
row=1, col=1,
)
fig.update_yaxes(
zeroline=True, zerolinecolor=GRID, zerolinewidth=1,
title_text="Imaginary",
scaleanchor="x", scaleratio=1,
row=1, col=1,
)
fig.update_xaxes(
zeroline=True, zerolinecolor=GRID, zerolinewidth=1,
title_text="Real",
range=[-1.5, 1.5],
row=1, col=2,
)
fig.update_yaxes(
zeroline=True, zerolinecolor=GRID, zerolinewidth=1,
title_text="Imaginary",
range=[-1.5, 1.5],
scaleanchor="x2", scaleratio=1,
row=1, col=2,
)
apply_theme(fig)
return fig
fig = generate()
fig.show()
Made with Plotly