Bode Plot Visualization
This module provides the BodePlot class for creating Bode plot visualizations of control systems.
BodePlot Class
- class BodePlot(system, freq_range=None, magnitude_yrange=None, phase_yrange=None, color=ManimColor('#58C4DD'), stroke_width=2.5, mag_label='Magnitude (dB)', phase_label='Phase (deg)', xlabel='Frequency (rad/s)', font_size_ylabels=20, font_size_xlabel=20, y_length_mag=None, y_length_phase=None, x_length=None, **kwargs)[source]
Bases:
VGroup- __init__(system, freq_range=None, magnitude_yrange=None, phase_yrange=None, color=ManimColor('#58C4DD'), stroke_width=2.5, mag_label='Magnitude (dB)', phase_label='Phase (deg)', xlabel='Frequency (rad/s)', font_size_ylabels=20, font_size_xlabel=20, y_length_mag=None, y_length_phase=None, x_length=None, **kwargs)[source]
Generates a Bode plot visualization as a Manim VGroup for continuous- or discrete-time systems.
This class takes a system representation (transfer function, poles/zeros, or state-space) and visualizes its frequency response with magnitude (in dB) and phase (in degrees) plots. It supports automatic range determination, customizable axes, grid display, and stability analysis.
- Parameters:
system (various) – System representation, which can be one of: - scipy.signal.lti or transfer function coefficients (list/tuple of arrays) - Symbolic expressions for numerator/denominator (using ‘s’ as variable) - Tuple of (numerator_expr, denominator_expr) as strings or sympy expressions
freq_range (tuple[float] | None) – Frequency range in rad/s as (min_freq, max_freq). If None, automatically determined.
magnitude_yrange (tuple[float] | None) – Magnitude range in dB as (min_db, max_db). If None, automatically determined.
phase_yrange (tuple[float] | None) – Phase range in degrees as (min_deg, max_deg). If None, automatically determined.
color (str) – Color of the Bode plot curves (default: BLUE).
stroke_width (float) – Stroke width of the plot curves (default: 2).
mag_label (str) – Label for the magnitude axis (default: “Magnitude (dB)”).
phase_label (str) – Label for the phase axis (default: “Phase (deg)”).
xlabel (str) – Label for the frequency axis (default: “Frequency (rad/s)”).
font_size_ylabels (int) – Font size for y-axis labels (default: 20).
font_size_xlabel (int) – Font size for x-axis label (default: 20).
y_length_mag (float) – The vertical length of the magnitude plot
y_length_phase (float) – The vertical length of the phase plot
x_length (float) – The horizontal length of the plots
**kwargs (Any) – Additional keyword arguments passed to the VGroup constructor.
- Returns:
A Manim VGroup containing: - Magnitude plot with logarithmic frequency axis and linear dB scale - Phase plot with logarithmic frequency axis and linear degree scale - Axis labels and ticks - Optional grid lines, title, and stability indicators
- Return type:
VGroup
- show_magnitude(show=True)[source]
Show or hide the magnitude plot and all its components. :param show: If true shows the magnitude plot :type show: bool
- show_phase(show=True)[source]
Show or hide the phase plot and all its components. :param show: If true shows the phase plot :type show: bool
- title(text, font_size=30, color=ManimColor('#FFFFFF'), use_math_tex=False)[source]
Add a title to the Bode plot.
- Parameters:
text (str) – The title
font_size (float) – Font size of the title
use_math_tex (bool) – Boolean which determines whether to render as LaTeX or regular text
- show_asymptotes(color=ManimColor('#F7D96F'), add_directly=True, **kwargs)[source]
Plot asymptotes of the Bode plot.
- Parameters:
color (Manim color) – Color of the asymptotes
add_directly (bool) – If true, the asymptotes are added directly to the Bode plot. To animate the asymptotes set add_directly to false
**kwargs (any) – Any arguments to be passed to Line: -stroke_width: Thickness of the asymptote lines -stroke_opacity: Opacity of the asymptote lines
- show_margins(show_values=True, show_pm=True, show_gm=True, gm_in_dB=True, pm_color=ManimColor('#83C167'), add_directly=True, gm_color=ManimColor('#F7D96F'), text_color_white=True, font_size=24, gm_label=None, pm_label=None, pm_label_pos=array([-1., -1., 0.]), gm_label_pos=array([1., 1., 0.]), **kwargs)[source]
Shows gain and phase margins on the Bode plot if finite.
- Parameters:
show_values (Whether to display the numerical values of the margins)
margin_color (-)
text_color (-)
- __init__(system, freq_range=None, magnitude_yrange=None, phase_yrange=None, color=ManimColor('#58C4DD'), stroke_width=2.5, mag_label='Magnitude (dB)', phase_label='Phase (deg)', xlabel='Frequency (rad/s)', font_size_ylabels=20, font_size_xlabel=20, y_length_mag=None, y_length_phase=None, x_length=None, **kwargs)[source]
Generates a Bode plot visualization as a Manim VGroup for continuous- or discrete-time systems.
This class takes a system representation (transfer function, poles/zeros, or state-space) and visualizes its frequency response with magnitude (in dB) and phase (in degrees) plots. It supports automatic range determination, customizable axes, grid display, and stability analysis.
- Parameters:
system (various) – System representation, which can be one of: - scipy.signal.lti or transfer function coefficients (list/tuple of arrays) - Symbolic expressions for numerator/denominator (using ‘s’ as variable) - Tuple of (numerator_expr, denominator_expr) as strings or sympy expressions
freq_range (tuple[float] | None) – Frequency range in rad/s as (min_freq, max_freq). If None, automatically determined.
magnitude_yrange (tuple[float] | None) – Magnitude range in dB as (min_db, max_db). If None, automatically determined.
phase_yrange (tuple[float] | None) – Phase range in degrees as (min_deg, max_deg). If None, automatically determined.
color (str) – Color of the Bode plot curves (default: BLUE).
stroke_width (float) – Stroke width of the plot curves (default: 2).
mag_label (str) – Label for the magnitude axis (default: “Magnitude (dB)”).
phase_label (str) – Label for the phase axis (default: “Phase (deg)”).
xlabel (str) – Label for the frequency axis (default: “Frequency (rad/s)”).
font_size_ylabels (int) – Font size for y-axis labels (default: 20).
font_size_xlabel (int) – Font size for x-axis label (default: 20).
y_length_mag (float) – The vertical length of the magnitude plot
y_length_phase (float) – The vertical length of the phase plot
x_length (float) – The horizontal length of the plots
**kwargs (Any) – Additional keyword arguments passed to the VGroup constructor.
- Returns:
A Manim VGroup containing: - Magnitude plot with logarithmic frequency axis and linear dB scale - Phase plot with logarithmic frequency axis and linear degree scale - Axis labels and ticks - Optional grid lines, title, and stability indicators
- Return type:
VGroup
- animation_overrides = {}
- show_asymptotes(color=ManimColor('#F7D96F'), add_directly=True, **kwargs)[source]
Plot asymptotes of the Bode plot.
- Parameters:
color (Manim color) – Color of the asymptotes
add_directly (bool) – If true, the asymptotes are added directly to the Bode plot. To animate the asymptotes set add_directly to false
**kwargs (any) – Any arguments to be passed to Line: -stroke_width: Thickness of the asymptote lines -stroke_opacity: Opacity of the asymptote lines
- show_magnitude(show=True)[source]
Show or hide the magnitude plot and all its components. :param show: If true shows the magnitude plot :type show: bool
- show_margins(show_values=True, show_pm=True, show_gm=True, gm_in_dB=True, pm_color=ManimColor('#83C167'), add_directly=True, gm_color=ManimColor('#F7D96F'), text_color_white=True, font_size=24, gm_label=None, pm_label=None, pm_label_pos=array([-1., -1., 0.]), gm_label_pos=array([1., 1., 0.]), **kwargs)[source]
Shows gain and phase margins on the Bode plot if finite.
- Parameters:
show_values (Whether to display the numerical values of the margins)
margin_color (-)
text_color (-)
System Input Formats
The BodePlot class accepts multiple system representation formats:
Scipy LTI objects:
signal.TransferFunction,signal.ZerosPolesGain,signal.StateSpaceCoefficient tuples:
(numerator_coeffs, denominator_coeffs)Symbolic expressions: Strings or sympy expressions using ‘s’ as variable
Transfer function strings:
"s/(s^2 + 1)"or"s/(s^2 + 1)/1"
Notes
The class automatically handles phase unwrapping and DC gain alignment
Frequency ranges are automatically determined based on system poles/zeros
Grid lines and labels are dynamically scaled based on plot ranges