Plotting (evopt.plotting)
The plotting module provides visualization functions for optimization results.
Classes
- class evopt.plotting.Plotting[source]
Bases:
objectVisualization tools for evolutionary optimization results.
This class provides static methods for visualizing results from evolutionary optimization runs. It can generate plots showing the evolution of parameters across epochs, parameter convergence, and explore relationships between parameters through various visualization techniques.
The class operates on the CSV result files produced during optimization runs, which contain information about individual evaluations and epoch statistics.
Examples
Create epoch plots showing parameter evolution:
>>> Plotting.plot_epochs("path/to/evolve_dir")
Create a 1-D scatterplot visualization of two parameters:
>>> Plotting.plot_vars("path/to/evolve_dir", x = "param1", y = "param2")
Create a 2-D Voronoi plot visualization with parameter values:
>>> Plotting.plot_vars("path/to/evolve_dir", x = "param1", y = "param2", cval = "error")
Create a 3-D surface plot visualization with parameter values:
>>> Plotting.plot_vars("path/to/evolve_dir", x = "param1", y = "param2", z = "param3")
Create a 3-D surface plot visualization with parameter values and color:
>>> Plotting.plot_vars("path/to/evolve_dir", x = "param1", y = "param2", z = "param3", cval = "error")
Epoch Visualization
- static plot_epochs(evolve_dir_path: str, show: bool = True, save_dir: str | None = None, save_ext: str = '.png', cmap: str = 'Dark2', point_alpha: float | int = 0.75, shade_alpha: float | int = 0.4, save_figures: bool = True)[source]
Plot the mean and sigma values for each parameter across epochs.
Creates visualizations showing how parameters evolved during optimization. For each parameter, this method generates a plot showing: - The mean value across epochs (line) - The individual evaluation results (scattered points) - The standard deviation ranges (shaded areas)
Additionally, generates a convergence plot showing normalized sigma values.
- Parameters:
evolve_dir_path – Path to the directory containing the evolution data files.
show – Whether to display the plots in the current interface.
save_dir – Directory to save the plot files. If None, creates a ‘figures’ subdirectory in evolve_dir_path.
save_ext – File extension for saved plots. Must be one of ‘png’, ‘jpg’, ‘jpeg’, ‘pdf’, or ‘svg’.
cmap – Matplotlib colormap name to use for the plots.
point_alpha – Opacity of the scattered points (0.0-1.0).
shade_alpha – Opacity of the standard deviation shaded areas (0.0-1.0).
save_figures – Whether to save the generated figures to disk.
- Returns:
None
- Raises:
FileNotFoundError – If the required CSV files are not found.
ValueError – If an invalid file extension is provided.
Parameter Space Visualization
- static plot_vars(evolve_dir_path: str, x: str, y: str, z: str | None = None, cval: str | None = None, show: bool = True, save_dir: str | None = None, save_ext: str = '.png', cmap: str = 'viridis', point_colour: str = 'black', alpha: float | int = 1, save_figures: bool = True, title: str | None = None, xlabel: str | None = None, ylabel: str | None = None, zlabel: str | None = None, cval_label: str | None = None)[source]
Visualize relationships between optimization parameters and results.
Creates visualizations to explore the relationships between parameters and results. The visualization type depends on the provided parameters:
If only x and y are provided: Creates a 2D scatter plot
If x, y, and cval are provided: Creates a Voronoi diagram with regions colored by cval
If x, y, and z are provided: Creates a 3D surface plot of x, y, z
If x, y, z, and cval are provided: Creates a 3D surface with color determined by cval
- Parameters:
evolve_dir_path – Path to the directory containing evolution data.
x – Column name for x-axis values.
y – Column name for y-axis values.
z – Column name for z-axis values (for 3D plots). Defaults to None.
cval – Column name for values used to color the plot. Defaults to None.
show – Whether to display the plots in the current interface.
save_dir – Directory to save the plots. If None, creates a ‘figures’ subdirectory in evolve_dir_path.
save_ext – File extension for saved plots (‘png’, ‘jpg’, ‘jpeg’, ‘pdf’, ‘svg’). For 3D plots, always saved as HTML regardless of this setting.
cmap – Colormap name to use for the plots.
point_colour – Color for scatter points.
alpha – Opacity of plot elements (0.0-1.0).
save_figures – Whether to save the generated figures to disk.
- Returns:
Either a matplotlib Axes object (for 2D plots) or a plotly Figure object (for 3D plots).
- Raises:
FileNotFoundError – If the required CSV files are not found.
ValueError – If invalid parameters are provided or file extension is invalid.