plotting – Visualization
Plotting module for DifferentialLab.
- plotting.create_contour_plot(x, y, z, title='f(x, y)', xlabel='x', ylabel='f')[source]
Create a 2D contour plot for 2D scalar field data.
- plotting.create_energy_evolution_plot(t, E_kin, E_pot, E_tot, title='Energy vs time', xlabel='t')[source]
Create a plot of kinetic, potential, and total energy vs time.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.create_energy_per_mode_plot(t, E_modes, selected_indices, labels, title='Energy per mode', xlabel='t')[source]
Create a multi-line plot of energy per mode (or oscillator) vs time.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.create_phase_3d_plot(data_x, data_y, data_z, title='Phase Space 3D', xlabel='f₀', ylabel='f₁', zlabel='f₂')[source]
Create a 3D phase-space trajectory plot.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.create_phase_plot(y, title='Phase Portrait', xlabel='f', ylabel="f'", x=None)[source]
Create a phase portrait for an ODE.
For second-order (or higher): plots y vs y’ (position vs velocity). For first-order: plots y vs dy/dx using numerical derivative (requires x).
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.create_solution_plot(x, y, title='f(x)', xlabel='x', ylabel='f', show_markers=False, selected_derivatives=None, labels=None)[source]
Create a publication-ready plot of the ODE solution.
- Parameters:
x (
ndarray) – Independent variable values.y (
ndarray) – Solution values — shape(n_vars, n_points)or(n_points,).title (
str) – Plot title.xlabel (
str) – Label for x-axis.ylabel (
str) – Label for y-axis.show_markers (
bool) – Whether to overlay data-point markers.selected_derivatives (
list[int] |None) – Indices of solution components to plot.labels (
list[str] |None) – Custom legend labels for each derivative (f-notation).
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.create_surface_plot(x, y, z, title='f(x, y)', xlabel='x', ylabel='y', zlabel='f')[source]
Create a 3D surface plot for 2D scalar field data.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.create_vector_animation_3d(x, y, order, vector_components, title='f_i(x) — 3D', deriv_offset=0)[source]
Create a 3D plot: x (independent), component index i, f_i(x).
- Parameters:
- Return type:
- Returns:
A matplotlib Figure with 3D surface.
- plotting.create_vector_animation_plot(x, y, order, vector_components, title='f_i(x) vs component', deriv_offset=0, component_labels=None)[source]
Create an interactive plot: x-axis = component index i, y-axis = f_i(x).
The figure stores _animation_update(idx) and _animation_n_points for use with a Tkinter Scale (matplotlib Slider is unreliable when embedded in Tk). For vector ODE: y has shape (n_state, n_points), with f_i at y[i*order].
- Parameters:
- Return type:
- Returns:
A matplotlib Figure (use with embed_animation_plot_in_tk).
- plotting.export_animation_to_mp4(x, y, order, vector_components, filepath, *, title='f_i(x) vs component', duration_seconds=10.0, deriv_offset=0)[source]
Export vector animation as MP4 video.
Frames are downsampled to at most _MAX_MP4_FRAMES to avoid memory exhaustion. Requires ffmpeg to be installed on the system.
- Parameters:
x (
ndarray) – Independent variable values.y (
ndarray) – Solution array, shape (n_state, n_points).order (
int) – Order per component.vector_components (
int) – Number of components.filepath (
Path) – Output path for the MP4 file.title (
str) – Plot title.duration_seconds (
float) – Desired video duration in seconds. FPS is computed.deriv_offset (int)
- Return type:
- Returns:
The path that was written.
- Raises:
RuntimeError – If ffmpeg is not available.
plotting.plot_utils
Matplotlib plotting utilities for ODE solutions.
- plotting.plot_utils.create_solution_plot(x, y, title='f(x)', xlabel='x', ylabel='f', show_markers=False, selected_derivatives=None, labels=None)[source]
Create a publication-ready plot of the ODE solution.
- Parameters:
x (
ndarray) – Independent variable values.y (
ndarray) – Solution values — shape(n_vars, n_points)or(n_points,).title (
str) – Plot title.xlabel (
str) – Label for x-axis.ylabel (
str) – Label for y-axis.show_markers (
bool) – Whether to overlay data-point markers.selected_derivatives (
list[int] |None) – Indices of solution components to plot.labels (
list[str] |None) – Custom legend labels for each derivative (f-notation).
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.plot_utils.create_energy_evolution_plot(t, E_kin, E_pot, E_tot, title='Energy vs time', xlabel='t')[source]
Create a plot of kinetic, potential, and total energy vs time.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.plot_utils.create_energy_per_mode_plot(t, E_modes, selected_indices, labels, title='Energy per mode', xlabel='t')[source]
Create a multi-line plot of energy per mode (or oscillator) vs time.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.plot_utils.create_phase_plot(y, title='Phase Portrait', xlabel='f', ylabel="f'", x=None)[source]
Create a phase portrait for an ODE.
For second-order (or higher): plots y vs y’ (position vs velocity). For first-order: plots y vs dy/dx using numerical derivative (requires x).
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.plot_utils.create_phase_3d_plot(data_x, data_y, data_z, title='Phase Space 3D', xlabel='f₀', ylabel='f₁', zlabel='f₂')[source]
Create a 3D phase-space trajectory plot.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.plot_utils.create_surface_plot(x, y, z, title='f(x, y)', xlabel='x', ylabel='y', zlabel='f')[source]
Create a 3D surface plot for 2D scalar field data.
- Parameters:
- Return type:
- Returns:
A matplotlib
Figure.
- plotting.plot_utils.create_contour_plot(x, y, z, title='f(x, y)', xlabel='x', ylabel='f')[source]
Create a 2D contour plot for 2D scalar field data.
- plotting.plot_utils.create_vector_animation_plot(x, y, order, vector_components, title='f_i(x) vs component', deriv_offset=0, component_labels=None)[source]
Create an interactive plot: x-axis = component index i, y-axis = f_i(x).
The figure stores _animation_update(idx) and _animation_n_points for use with a Tkinter Scale (matplotlib Slider is unreliable when embedded in Tk). For vector ODE: y has shape (n_state, n_points), with f_i at y[i*order].
- Parameters:
- Return type:
- Returns:
A matplotlib Figure (use with embed_animation_plot_in_tk).
- plotting.plot_utils.create_vector_animation_3d(x, y, order, vector_components, title='f_i(x) — 3D', deriv_offset=0)[source]
Create a 3D plot: x (independent), component index i, f_i(x).
- Parameters:
- Return type:
- Returns:
A matplotlib Figure with 3D surface.
- plotting.plot_utils.export_animation_to_mp4(x, y, order, vector_components, filepath, *, title='f_i(x) vs component', duration_seconds=10.0, deriv_offset=0)[source]
Export vector animation as MP4 video.
Frames are downsampled to at most _MAX_MP4_FRAMES to avoid memory exhaustion. Requires ffmpeg to be installed on the system.
- Parameters:
x (
ndarray) – Independent variable values.y (
ndarray) – Solution array, shape (n_state, n_points).order (
int) – Order per component.vector_components (
int) – Number of components.filepath (
Path) – Output path for the MP4 file.title (
str) – Plot title.duration_seconds (
float) – Desired video duration in seconds. FPS is computed.deriv_offset (int)
- Return type:
- Returns:
The path that was written.
- Raises:
RuntimeError – If ffmpeg is not available.