Visualization API¶
Plotting functions for trade study visualization.
Overview¶
from phased_array_systems.viz import pareto_plot, scatter_matrix, trade_space_plot
# Also available from submodule
from phased_array_systems.viz.plots import save_figure
Functions¶
pareto_plot
¶
pareto_plot(results: DataFrame, x: str, y: str, pareto_front: DataFrame | None = None, feasible_mask: Series | None = None, color_by: str | None = None, size_by: str | None = None, ax: Axes | None = None, title: str | None = None, x_label: str | None = None, y_label: str | None = None, show_pareto_line: bool = True, figsize: tuple[float, float] = (8, 6)) -> Figure
Create a Pareto plot showing trade-offs between two objectives.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
DataFrame with all evaluation results
TYPE:
|
x
|
Column name for x-axis
TYPE:
|
y
|
Column name for y-axis
TYPE:
|
pareto_front
|
Optional DataFrame with Pareto-optimal points to highlight
TYPE:
|
feasible_mask
|
Optional boolean Series marking feasible designs
TYPE:
|
color_by
|
Optional column name to color points by
TYPE:
|
size_by
|
Optional column name to size points by
TYPE:
|
ax
|
Optional existing Axes to plot on
TYPE:
|
title
|
Plot title
TYPE:
|
x_label
|
X-axis label (defaults to column name)
TYPE:
|
y_label
|
Y-axis label (defaults to column name)
TYPE:
|
show_pareto_line
|
If True, draw line connecting Pareto points
TYPE:
|
figsize
|
Figure size (width, height)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
matplotlib Figure object |
Source code in src/phased_array_systems/viz/plots.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
scatter_matrix
¶
scatter_matrix(results: DataFrame, columns: list[str], color_by: str | None = None, diagonal: Literal['hist', 'kde'] = 'hist', figsize: tuple[float, float] | None = None, title: str | None = None) -> Figure
Create a scatter matrix showing pairwise relationships.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
DataFrame with evaluation results
TYPE:
|
columns
|
List of column names to include
TYPE:
|
color_by
|
Optional column name to color points by
TYPE:
|
diagonal
|
What to show on diagonal ("hist" or "kde")
TYPE:
|
figsize
|
Figure size (auto-calculated if None)
TYPE:
|
title
|
Overall figure title
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
matplotlib Figure object |
Source code in src/phased_array_systems/viz/plots.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
trade_space_plot
¶
trade_space_plot(results: DataFrame, x: str, y: str, z: str, feasible_mask: Series | None = None, pareto_front: DataFrame | None = None, ax: Axes | None = None, figsize: tuple[float, float] = (10, 8), title: str | None = None) -> Figure
Create a 3D trade space visualization.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
DataFrame with evaluation results
TYPE:
|
x
|
Column name for x-axis
TYPE:
|
y
|
Column name for y-axis
TYPE:
|
z
|
Column name for z-axis (color)
TYPE:
|
feasible_mask
|
Optional boolean mask for feasible designs
TYPE:
|
pareto_front
|
Optional DataFrame with Pareto-optimal points
TYPE:
|
ax
|
Optional existing 3D Axes
TYPE:
|
figsize
|
Figure size
TYPE:
|
title
|
Plot title
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
matplotlib Figure object |
Source code in src/phased_array_systems/viz/plots.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
save_figure
¶
Save a figure to file.
| PARAMETER | DESCRIPTION |
|---|---|
fig
|
matplotlib Figure to save
TYPE:
|
path
|
Output path (extension determines format)
TYPE:
|
dpi
|
Resolution for raster formats
TYPE:
|
transparent
|
Whether to use transparent background
TYPE:
|
Source code in src/phased_array_systems/viz/plots.py
Usage Examples¶
Pareto Plot¶
from phased_array_systems.viz import pareto_plot
from phased_array_systems.trades import extract_pareto
# Extract Pareto frontier
pareto = extract_pareto(results, [("cost_usd", "minimize"), ("eirp_dbw", "maximize")])
# Create feasibility mask
feasible_mask = results["verification.passes"] == 1.0
# Generate plot
fig = pareto_plot(
results,
x="cost_usd",
y="eirp_dbw",
pareto_front=pareto,
feasible_mask=feasible_mask,
color_by="link_margin_db",
title="Cost vs EIRP Trade Space",
x_label="Total Cost (USD)",
y_label="EIRP (dBW)",
)
fig.savefig("pareto.png", dpi=150, bbox_inches="tight")
Scatter Matrix¶
from phased_array_systems.viz import scatter_matrix
fig = scatter_matrix(
feasible,
columns=["cost_usd", "eirp_dbw", "link_margin_db", "prime_power_w"],
color_by="n_elements",
diagonal="hist",
title="Trade Space Correlations",
)
fig.savefig("scatter.png", dpi=150)
3D Trade Space¶
from phased_array_systems.viz import trade_space_plot
fig = trade_space_plot(
results,
x="cost_usd",
y="eirp_dbw",
z="prime_power_w",
feasible_mask=feasible_mask,
pareto_front=pareto_3d,
title="3D Trade Space",
)
fig.savefig("trade_space_3d.png", dpi=150)
Multi-Panel Figure¶
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(14, 6))
pareto_plot(results, x="cost_usd", y="eirp_dbw", ax=axes[0])
pareto_plot(results, x="cost_usd", y="link_margin_db", ax=axes[1])
fig.tight_layout()
fig.savefig("combined.png", dpi=150)
Saving Figures¶
from phased_array_systems.viz import save_figure
fig = pareto_plot(results, x="cost_usd", y="eirp_dbw")
# Various formats
save_figure(fig, "plot.png", dpi=150)
save_figure(fig, "plot.pdf")
save_figure(fig, "plot.svg")
save_figure(fig, "plot_transparent.png", transparent=True)
Plot Customization¶
Adding Annotations¶
fig = pareto_plot(results, x="cost_usd", y="eirp_dbw")
ax = fig.axes[0]
# Add reference lines
ax.axhline(y=40, color='r', linestyle='--', label='Min EIRP')
ax.axvline(x=50000, color='g', linestyle='--', label='Budget')
# Add annotation
ax.annotate(
"Target Region",
xy=(40000, 45),
xytext=(55000, 50),
arrowprops=dict(arrowstyle="->"),
)
ax.legend()
Custom Color Maps¶
fig = pareto_plot(
results,
x="cost_usd",
y="eirp_dbw",
color_by="link_margin_db",
)
# Access scatter for custom colorbar
ax = fig.axes[0]
# Colorbar is automatically added when color_by is specified
Non-Interactive Usage¶
For scripts without display:
import matplotlib
matplotlib.use("Agg") # Must be before pyplot import
import matplotlib.pyplot as plt
from phased_array_systems.viz import pareto_plot
fig = pareto_plot(results, x="cost_usd", y="eirp_dbw")
fig.savefig("output.png", dpi=150)
plt.close(fig) # Release memory