scientific-skills/pymoo/references/visualization.md
Comprehensive reference for visualization capabilities in pymoo.
Pymoo provides eight visualization types for analyzing multi-objective optimization results. All plots wrap matplotlib and accept standard matplotlib keyword arguments for customization.
Purpose: Visualize objective space for 2D, 3D, or higher dimensions Best for: Pareto fronts, solution distributions, algorithm comparisons
Usage:
from pymoo.visualization.scatter import Scatter
# 2D scatter plot
plot = Scatter()
plot.add(result.F, color="red", label="Algorithm A")
plot.add(ref_pareto_front, color="black", alpha=0.3, label="True PF")
plot.show()
# 3D scatter plot
plot = Scatter(title="3D Pareto Front")
plot.add(result.F)
plot.show()
Parameters:
title: Plot titlefigsize: Figure size tuple (width, height)legend: Show legend (default: True)labels: Axis labels listAdd method parameters:
color: Color specificationalpha: Transparency (0-1)s: Marker sizemarker: Marker stylelabel: Legend labelN-dimensional projection: For >3 objectives, automatically creates scatter plot matrix
Purpose: Compare multiple solutions across many objectives Best for: Many-objective problems, comparing algorithm performance
Mechanism: Each vertical axis represents one objective, lines connect objective values for each solution
Usage:
from pymoo.visualization.pcp import PCP
plot = PCP()
plot.add(result.F, color="blue", alpha=0.5)
plot.add(reference_set, color="red", alpha=0.8)
plot.show()
Parameters:
title: Plot titlefigsize: Figure sizelabels: Objective labelsbounds: Normalization bounds (min, max) per objectivenormalize_each_axis: Normalize to [0,1] per axis (default: True)Best practices:
Purpose: Show solution density and distribution patterns Best for: Understanding solution clustering, identifying gaps
Usage:
from pymoo.visualization.heatmap import Heatmap
plot = Heatmap(title="Solution Density")
plot.add(result.F)
plot.show()
Parameters:
bins: Number of bins per dimension (default: 20)cmap: Colormap name (e.g., "viridis", "plasma", "hot")norm: Normalization methodInterpretation:
Purpose: Radial representation of multiple objectives Best for: Comparing individual solutions across objectives
Structure: Each "petal" represents one objective, length indicates objective value
Usage:
from pymoo.visualization.petal import Petal
plot = Petal(title="Solution Comparison", bounds=[min_vals, max_vals])
plot.add(result.F[0], color="blue", label="Solution 1")
plot.add(result.F[1], color="red", label="Solution 2")
plot.show()
Parameters:
bounds: [min, max] per objective for normalizationlabels: Objective namesreverse: Reverse specific objectives (for minimization display)Use cases:
Purpose: Multi-criteria performance profiles Best for: Comparing solution characteristics
Similar to: Petal diagram but with connected vertices
Usage:
from pymoo.visualization.radar import Radar
plot = Radar(bounds=[min_vals, max_vals])
plot.add(solution_A, label="Design A")
plot.add(solution_B, label="Design B")
plot.show()
Purpose: Dimensional reduction for visualization Best for: High-dimensional data exploration, pattern recognition
Mechanism: Projects high-dimensional points onto 2D circle, dimension anchors on perimeter
Usage:
from pymoo.visualization.radviz import Radviz
plot = Radviz(title="High-dimensional Solution Space")
plot.add(result.F, color="blue", s=30)
plot.show()
Parameters:
endpoint_style: Anchor point visualizationlabels: Dimension labelsInterpretation:
Purpose: Alternative high-dimensional visualization Best for: Comparing multi-dimensional datasets
Mechanism: Each dimension as axis from origin, points plotted based on values
Usage:
from pymoo.visualization.star_coordinate import StarCoordinate
plot = StarCoordinate()
plot.add(result.F)
plot.show()
Parameters:
axis_style: Axis appearanceaxis_extension: Axis length beyond max valuelabels: Dimension labelsPurpose: Show optimization progress over time Best for: Understanding convergence behavior, presentations
Usage:
from pymoo.visualization.video import Video
# Create animation from algorithm history
anim = Video(result.algorithm)
anim.save("optimization_progress.mp4")
Requirements:
save_history=True in minimize)Customization:
All plot types support adding multiple datasets:
plot = Scatter(title="Algorithm Comparison")
plot.add(nsga2_result.F, color="red", alpha=0.5, label="NSGA-II")
plot.add(nsga3_result.F, color="blue", alpha=0.5, label="NSGA-III")
plot.add(true_pareto_front, color="black", linewidth=2, label="True PF")
plot.show()
Pass matplotlib kwargs directly:
plot = Scatter(
title="My Results",
figsize=(10, 8),
tight_layout=True
)
plot.add(
result.F,
color="red",
marker="o",
s=50,
alpha=0.7,
edgecolors="black",
linewidth=0.5
)
Normalize objectives to [0,1] for fair comparison:
plot = PCP(normalize_each_axis=True, bounds=[min_bounds, max_bounds])
Save plots instead of displaying:
plot = Scatter()
plot.add(result.F)
plot.save("my_plot.png", dpi=300)
Choose visualization based on:
| Problem Type | Primary Plot | Secondary Plot |
|---|---|---|
| 2-objective | Scatter | Heatmap |
| 3-objective | 3D Scatter | Parallel Coordinates |
| Many-objective (4-10) | Parallel Coordinates | Radviz |
| Many-objective (>10) | Radviz | Star Coordinates |
| Solution comparison | Petal/Radar | Parallel Coordinates |
| Algorithm convergence | Video | Scatter (final) |
| Distribution analysis | Heatmap | Scatter |
Combinations:
from pymoo.visualization.scatter import Scatter
plot = Scatter(title="Algorithm Comparison on ZDT1")
plot.add(ga_result.F, color="blue", label="GA", alpha=0.6)
plot.add(nsga2_result.F, color="red", label="NSGA-II", alpha=0.6)
plot.add(zdt1.pareto_front(), color="black", label="True PF")
plot.show()
from pymoo.visualization.pcp import PCP
plot = PCP(
title="5-objective DTLZ2 Results",
labels=["f1", "f2", "f3", "f4", "f5"],
normalize_each_axis=True
)
plot.add(result.F, alpha=0.3)
plot.show()
from pymoo.visualization.petal import Petal
# Compare top 3 solutions
candidates = result.F[:3]
plot = Petal(
title="Top 3 Solutions",
bounds=[result.F.min(axis=0), result.F.max(axis=0)],
labels=["Cost", "Weight", "Efficiency", "Safety"]
)
for i, sol in enumerate(candidates):
plot.add(sol, label=f"Solution {i+1}")
plot.show()
from pymoo.optimize import minimize
# Enable history
result = minimize(
problem,
algorithm,
('n_gen', 200),
seed=1,
save_history=True,
verbose=False
)
# Create convergence plot
from pymoo.visualization.scatter import Scatter
plot = Scatter(title="Convergence Over Generations")
for gen in [0, 50, 100, 150, 200]:
F = result.history[gen].opt.get("F")
plot.add(F, alpha=0.5, label=f"Gen {gen}")
plot.show()
alpha=0.3-0.7dpi=300 for publications