Visualization (pypielm.visualization)¶
Visualisation utilities (requires pip install pypielm[viz]).
Public surface:
from pypielm.visualization import (
plot_solution_1d,
plot_solution_2d,
plot_training_history,
plot_pareto,
plot_leaderboard_heatmap,
save_figure,
)
- pypielm.visualization.plot_solution_1d(x, u_pred, u_true=None, *, xlabel='x', ylabel='u(x)', title='Solution', figsize=(7, 4), ax=None)[source]¶
Plot a 1D PDE solution (predicted vs. reference).
- Parameters:
x (
Any) – Coordinate array, shape(N,).u_pred (
Any) – Predicted solution, shape(N,).u_true (
Any|None) – Optional reference solution for comparison.xlabel (
str) – X-axis label.ylabel (
str) – Y-axis label.title (
str) – Figure title.figsize (
tuple[float,float]) – Figure size in inches (ignored when ax is provided).ax (
Any) – ExistingAxesto draw on. IfNonea new figure is created.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plot_solution_2d(x, u_pred, u_true=None, *, nx=64, ny=64, cmap='viridis', title='Solution', figsize=(12, 4), fig=None)[source]¶
Plot a 2D PDE solution as colour maps.
- Parameters:
x (
Any) – Coordinate array, shape(N, 2). Columns are[x, y].u_pred (
Any) – Predicted solution, shape(N,)or(N, 1).u_true (
Any|None) – Optional reference solution, same shape as u_pred.nx (
int) – Grid resolution along x-axis for interpolation.ny (
int) – Grid resolution along y-axis for interpolation.cmap (
str) – Colour map name.title (
str) – Figure suptitle.figsize (
tuple[float,float]) – Figure size in inches (ignored when fig is provided).fig (
Any) – ExistingFigure. IfNonea new figure is created.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plot_training_history(losses, *, log_scale=True, title='Training History', figsize=(7, 4), ax=None)[source]¶
Plot training loss curves.
- Parameters:
losses (
dict[str,list[float]]) – Dict mapping loss component names to lists of per-epoch values. Example:{"total": [...], "pde": [...], "bc": [...]}.log_scale (
bool) – IfTrue, use log scale on the y-axis.title (
str) – Figure title.figsize (
tuple[float,float]) – Figure size in inches (ignored when ax is provided).ax (
Any) – ExistingAxes.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plot_pareto(results, *, x_metric='fit_time_s', y_metric='rel_l2', label_key='model', log_x=False, log_y=True, figsize=(8, 5), ax=None)[source]¶
Pareto-front scatter plot: accuracy vs. runtime.
- Parameters:
results (
list[dict[str,Any]]) – List of dicts; each must contain x_metric, y_metric, and label_key.x_metric (
str) – Column name for the x-axis (default: fit time).y_metric (
str) – Column name for the y-axis (default: relative L² error).label_key (
str) – Column name used as point labels.log_x (
bool) – Log scale on x-axis.log_y (
bool) – Log scale on y-axis.figsize (
tuple[float,float]) – Figure size (ignored when ax is provided).ax (
Any) – ExistingAxes.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plot_leaderboard_heatmap(df, *, metric='rel_l2', figsize=(12, 6), cmap='YlOrRd_r', title='Leaderboard Heatmap', fig=None)[source]¶
Heatmap of model × task performance.
- Parameters:
df (
Any) – A 2-D structure (numpy.ndarray,list[list], orpandas.DataFrame) with models as rows and tasks as columns, pre-aggregated to metric values. When aDataFrameis supplied, row/column labels are used.metric (
str) – Metric name used for the colour-bar label.figsize (
tuple[float,float]) – Figure size (ignored when fig is provided).cmap (
str) – Colour map (default green = good:YlOrRd_r).title (
str) – Figure title.fig (
Any) – ExistingFigure.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.save_figure(fig, path, *, dpi=300, bbox_inches='tight')[source]¶
Save a
matplotlib.figure.Figureto path.
Matplotlib-based visualisation utilities.
All functions accept torch.Tensor or NumPy arrays and produce
matplotlib.figure.Figure objects that can be shown interactively,
saved, or embedded in notebooks.
Requires: pip install pypielm[viz].
- pypielm.visualization.plots.plot_solution_1d(x, u_pred, u_true=None, *, xlabel='x', ylabel='u(x)', title='Solution', figsize=(7, 4), ax=None)[source]¶
Plot a 1D PDE solution (predicted vs. reference).
- Parameters:
x (
Any) – Coordinate array, shape(N,).u_pred (
Any) – Predicted solution, shape(N,).u_true (
Any|None) – Optional reference solution for comparison.xlabel (
str) – X-axis label.ylabel (
str) – Y-axis label.title (
str) – Figure title.figsize (
tuple[float,float]) – Figure size in inches (ignored when ax is provided).ax (
Any) – ExistingAxesto draw on. IfNonea new figure is created.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plots.plot_solution_2d(x, u_pred, u_true=None, *, nx=64, ny=64, cmap='viridis', title='Solution', figsize=(12, 4), fig=None)[source]¶
Plot a 2D PDE solution as colour maps.
- Parameters:
x (
Any) – Coordinate array, shape(N, 2). Columns are[x, y].u_pred (
Any) – Predicted solution, shape(N,)or(N, 1).u_true (
Any|None) – Optional reference solution, same shape as u_pred.nx (
int) – Grid resolution along x-axis for interpolation.ny (
int) – Grid resolution along y-axis for interpolation.cmap (
str) – Colour map name.title (
str) – Figure suptitle.figsize (
tuple[float,float]) – Figure size in inches (ignored when fig is provided).fig (
Any) – ExistingFigure. IfNonea new figure is created.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plots.plot_training_history(losses, *, log_scale=True, title='Training History', figsize=(7, 4), ax=None)[source]¶
Plot training loss curves.
- Parameters:
losses (
dict[str,list[float]]) – Dict mapping loss component names to lists of per-epoch values. Example:{"total": [...], "pde": [...], "bc": [...]}.log_scale (
bool) – IfTrue, use log scale on the y-axis.title (
str) – Figure title.figsize (
tuple[float,float]) – Figure size in inches (ignored when ax is provided).ax (
Any) – ExistingAxes.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plots.plot_pareto(results, *, x_metric='fit_time_s', y_metric='rel_l2', label_key='model', log_x=False, log_y=True, figsize=(8, 5), ax=None)[source]¶
Pareto-front scatter plot: accuracy vs. runtime.
- Parameters:
results (
list[dict[str,Any]]) – List of dicts; each must contain x_metric, y_metric, and label_key.x_metric (
str) – Column name for the x-axis (default: fit time).y_metric (
str) – Column name for the y-axis (default: relative L² error).label_key (
str) – Column name used as point labels.log_x (
bool) – Log scale on x-axis.log_y (
bool) – Log scale on y-axis.figsize (
tuple[float,float]) – Figure size (ignored when ax is provided).ax (
Any) – ExistingAxes.
- Return type:
- Returns:
matplotlib.figure.Figure.
- pypielm.visualization.plots.plot_leaderboard_heatmap(df, *, metric='rel_l2', figsize=(12, 6), cmap='YlOrRd_r', title='Leaderboard Heatmap', fig=None)[source]¶
Heatmap of model × task performance.
- Parameters:
df (
Any) – A 2-D structure (numpy.ndarray,list[list], orpandas.DataFrame) with models as rows and tasks as columns, pre-aggregated to metric values. When aDataFrameis supplied, row/column labels are used.metric (
str) – Metric name used for the colour-bar label.figsize (
tuple[float,float]) – Figure size (ignored when fig is provided).cmap (
str) – Colour map (default green = good:YlOrRd_r).title (
str) – Figure title.fig (
Any) – ExistingFigure.
- Return type:
- Returns:
matplotlib.figure.Figure.