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)."""
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,
)
return fig
if __name__ == "__main__":
generate()
Made with Plotly