[ PROMPT_NODE_27149 ]
Pymoo – Visualization
[ SKILL_DOCUMENTATION ]
# Pymoo Visualization Reference
Comprehensive reference for visualization capabilities in pymoo.
## Overview
Pymoo provides eight visualization types for analyzing multi-objective optimization results. All plots wrap matplotlib and accept standard matplotlib keyword arguments for customization.
## Core Visualization Types
### 1. Scatter Plots
**Purpose:** Visualize objective space for 2D, 3D, or higher dimensions
**Best for:** Pareto fronts, solution distributions, algorithm comparisons
**Usage:**
```python
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 title
- `figsize`: Figure size tuple (width, height)
- `legend`: Show legend (default: True)
- `labels`: Axis labels list
**Add method parameters:**
- `color`: Color specification
- `alpha`: Transparency (0-1)
- `s`: Marker size
- `marker`: Marker style
- `label`: Legend label
**N-dimensional projection:**
For >3 objectives, automatically creates scatter plot matrix
### 2. Parallel Coordinate Plots (PCP)
**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:**
```python
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 title
- `figsize`: Figure size
- `labels`: Objective labels
- `bounds`: Normalization bounds (min, max) per objective
- `normalize_each_axis`: Normalize to [0,1] per axis (default: True)
**Best practices:**
- Normalize for different objective scales
- Use transparency for overlapping lines
- Limit number of solutions for clarity (10) | Radviz | Star Coordinates |
| Solution comparison | Petal/Radar | Parallel Coordinates |
| Algorithm convergence | Video | Scatter (final) |
| Distribution analysis | Heatmap | Scatter |
**Combinations:**
- Scatter + Heatmap: Overall distribution + density
- PCP + Petal: Population overview + individual solutions
- Scatter + Video: Final result + convergence process
## Common Visualization Workflows
### 1. Algorithm Comparison
```python
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()
```
### 2. Many-objective Analysis
```python
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()
```
### 3. Decision Making
```python
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()
```
### 4. Convergence Visualization
```python
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()
```
## Tips and Best Practices
1. **Use appropriate alpha:** For overlapping points, use `alpha=0.3-0.7`
2. **Normalize objectives:** Different scales? Normalize for fair visualization
3. **Label clearly:** Always provide meaningful labels and legends
4. **Limit data points:** >10000 points? Sample or use heatmap
5. **Color schemes:** Use colorblind-friendly palettes
6. **Save high-res:** Use `dpi=300` for publications
7. **Interactive exploration:** Consider plotly for interactive plots
8. **Combine views:** Show multiple perspectives for comprehensive analysis
Source: claude-code-templates (MIT). See About Us for full credits.