geomexp.visualization package¶
Submodules¶
geomexp.visualization.visualization module¶
Visualization module for clustering algorithms.
Provides plotting utilities for clustering analysis with consistent styling. All visual
configuration flows through PlotStyle, which must be passed to
ClusterVisualizer to ensure uniform appearance across all figures.
- class geomexp.visualization.visualization.PlotStyle(figsize=(3.5, 3.5), dpi=300, point_size=1.5, center_size=15, center_linewidth=0.8, alpha_data=0.7, alpha_contour=0.15, color_palette=None, center_color='black', center_marker='o', arrow_color='black', arrow_linewidth=0.8, arrow_head_width=0.15, arrow_head_length=0.2, arrow_scale=1, contour_color='black', contour_linewidth=0.5, contour_alpha=0.9, curve_linewidth=0.8, curve_alpha=0.7, kde_color='gray', kde_linewidth=0.4, kde_alpha=0.6, loss_linewidth=1.0, decision_boundary_resolution=300, decision_boundary_show_points=True, decision_boundary_show_contour_lines=True, decision_boundary_show_centers=True, decision_boundary_show_regions=True, decision_boundary_color=None, axis_linewidth=0.6, grid_alpha=0.15, grid_linewidth=0.3, fontsize=9, use_latex=True)[source]¶
Bases:
objectCentral styling configuration for all cluster visualisations.
Every plot produced by
ClusterVisualizerreads its visual parameters from this object, ensuring that all figures in a study share a uniform appearance. Construct aPlotStyleinstance first, then pass it toClusterVisualizer(style).- Parameters:
dpi (int)
point_size (float)
center_size (float)
center_linewidth (float)
alpha_data (float)
alpha_contour (float)
center_color (str)
center_marker (str)
arrow_color (str)
arrow_linewidth (float)
arrow_head_width (float)
arrow_head_length (float)
arrow_scale (float)
contour_color (str)
contour_linewidth (float)
contour_alpha (float)
curve_linewidth (float)
curve_alpha (float)
kde_color (str)
kde_linewidth (float)
kde_alpha (float)
loss_linewidth (float)
decision_boundary_resolution (int)
decision_boundary_show_points (bool)
decision_boundary_show_contour_lines (bool)
decision_boundary_show_centers (bool)
decision_boundary_show_regions (bool)
decision_boundary_color (str | None)
axis_linewidth (float)
grid_alpha (float)
grid_linewidth (float)
fontsize (float)
use_latex (bool)
- figsize¶
Default figure size
(width, height)in inches.
- dpi¶
Resolution in dots per inch.
- point_size¶
Scatter point size for data points.
- center_size¶
Scatter point size for cluster centers.
- center_linewidth¶
Edge line width for center markers.
- alpha_data¶
Opacity of data points.
- alpha_contour¶
Opacity of coloured decision regions.
- color_palette¶
List of hex colour strings cycled over clusters.
- center_color¶
Colour of center markers.
- center_marker¶
Marker shape for centers.
- arrow_color¶
Colour of index vector arrows.
- arrow_linewidth¶
Line width of index vector arrows.
- arrow_head_width¶
Head width of index vector arrows.
- arrow_head_length¶
Head length of index vector arrows.
- arrow_scale¶
Multiplicative scaling applied to index vector arrows for visibility.
- contour_color¶
Colour of decision boundary lines.
- contour_linewidth¶
Line width of decision boundary contours.
- contour_alpha¶
Opacity of decision boundary contour lines.
- curve_linewidth¶
Line width of expectile level-set contours.
- curve_alpha¶
Opacity of expectile level-set contour lines.
- kde_color¶
Colour of KDE density contour lines.
- kde_linewidth¶
Line width of KDE density contour lines.
- kde_alpha¶
Opacity of KDE density contour lines.
- loss_linewidth¶
Line width of loss function curves.
- decision_boundary_resolution¶
Grid resolution for boundary computation.
- decision_boundary_show_points¶
Whether to overlay data points on boundary plots.
- decision_boundary_show_contour_lines¶
Whether to draw boundary contour lines.
- decision_boundary_show_centers¶
Whether to show center markers on boundary plots.
- decision_boundary_show_regions¶
Whether to fill decision regions with colour.
- decision_boundary_color¶
Override colour for boundary lines (
Noneuses palette).
- axis_linewidth¶
Width of axis spines and tick marks.
- grid_alpha¶
Opacity of grid lines.
- grid_linewidth¶
Width of grid lines.
- fontsize¶
Base font size for labels and titles.
- use_latex¶
Whether to enable LaTeX rendering via
text.usetex.
- class geomexp.visualization.visualization.ClusterVisualizer(style)[source]¶
Bases:
objectPlotting engine for cluster analysis visualisations.
All plotting methods read visual configuration from the
styleattribute. APlotStyleinstance must be passed at construction time; there is no default.Example
>>> style = PlotStyle(figsize=(5, 4), use_latex=False) >>> viz = ClusterVisualizer(style)
- plot_cluster_assignments(X, result, ax=None, show_centers=True, show_indices=True, show_legend=False, title=None)[source]¶
Plot data points coloured by cluster assignment.
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).result (
ClusterResult) – Clustering result.ax (
Axes|None) – Matplotlib axes (created ifNone).show_centers (
bool) – Whether to overlay center markers.show_indices (
bool) – Whether to draw index vector arrows.show_legend (
bool) – Whether to show a cluster legend.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_decision_boundaries(X, result, ax=None, title=None, resolution=None, show_points=None, show_contour_lines=None, show_centers=None, show_regions=None, x_lim=None, y_lim=None, boundary_color=None)[source]¶
Plot decision boundaries (and optionally regions, data points, centers).
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).result (
ClusterResult) – Clustering result.ax (
Axes|None) – Matplotlib axes (created ifNone).resolution (
int|None) – Grid resolution for boundary computation. Defaults toself.style.decision_boundary_resolution.show_points (
bool|None) – Overlay data points. Defaults to style setting.show_contour_lines (
bool|None) – Draw boundary contour lines. Defaults to style setting.show_centers (
bool|None) – Show center markers. Defaults to style setting.show_regions (
bool|None) – Fill decision regions with colour. Defaults to style setting.boundary_color (
str|None) – Override colour for boundary lines.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_density_contours(X, ax=None, title=None, levels=20, bandwidth=0.2)[source]¶
Plot KDE density contours of the data.
- Parameters:
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_density_with_boundaries(X, result, ax=None, title=None, resolution=300, kde_levels=20, kde_bandwidth=0.2, show_centers=True, x_lim=None, y_lim=None)[source]¶
Overlay KDE density contours with decision boundary lines.
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).result (
ClusterResult) – Clustering result.ax (
Axes|None) – Matplotlib axes (created ifNone).resolution (
int) – Grid resolution for boundary computation.kde_levels (
int) – Number of KDE contour levels.kde_bandwidth (
float) – KDE bandwidth parameter.show_centers (
bool) – Whether to overlay center markers.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_expectile_curves(center, index_vector, cost_levels=None, ax=None, title=None, show_index_arrow=True, curve_color=None, extent=3.0, resolution=300)[source]¶
Plot level curves of the expectile loss around a single center.
- Parameters:
center (
ndarray) – Center point of shape(2,).index_vector (
ndarray) – Index vector of shape(2,).cost_levels (
ndarray|None) – Loss values at which to draw contours.ax (
Axes|None) – Matplotlib axes (created ifNone).show_index_arrow (
bool) – Whether to draw the index vector arrow.curve_color (
str|None) – Override colour for contour lines.extent (
float) – Half-width of the plotting window aroundcenter.resolution (
int) – Grid resolution.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_loss_comparison(loss_functions, x_range=(-3, 3), n_points=300, ax=None, title=None, show_legend=True)[source]¶
Plot one-dimensional loss function comparisons.
- Parameters:
loss_functions (
list[tuple[str,Callable[[ndarray],ndarray]]]) – List of(name, callable)pairs.x_range (
tuple[float,float]) – Domain(x_min, x_max)for the plot.n_points (
int) – Number of evaluation points.ax (
Axes|None) – Matplotlib axes (created ifNone).show_legend (
bool) – Whether to display a legend.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- create_comparison_figure(X, results, plot_type='assignments', nrows=None, ncols=None, figsize=None, align_labels=True, **plot_kwargs)[source]¶
Create a multi-panel comparison figure.
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).results (
list[tuple[str,ClusterResult]]) – List of(name, ClusterResult)pairs for each panel.plot_type (
str) – One of"assignments","boundaries", or"density".nrows (
int|None) – Number of subplot rows (inferred ifNone).ncols (
int|None) – Number of subplot columns (inferred ifNone).figsize (
tuple[float,float] |None) – Override figure size.align_labels (
bool) – Whether to align cluster labels across panels via permutation matching.**plot_kwargs (
Any) – Extra keyword arguments forwarded to the per-panel plot method.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the comparison.
Module contents¶
Visualization utilities module.
- class geomexp.visualization.ClusterVisualizer(style)[source]¶
Bases:
objectPlotting engine for cluster analysis visualisations.
All plotting methods read visual configuration from the
styleattribute. APlotStyleinstance must be passed at construction time; there is no default.Example
>>> style = PlotStyle(figsize=(5, 4), use_latex=False) >>> viz = ClusterVisualizer(style)
- plot_cluster_assignments(X, result, ax=None, show_centers=True, show_indices=True, show_legend=False, title=None)[source]¶
Plot data points coloured by cluster assignment.
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).result (
ClusterResult) – Clustering result.ax (
Axes|None) – Matplotlib axes (created ifNone).show_centers (
bool) – Whether to overlay center markers.show_indices (
bool) – Whether to draw index vector arrows.show_legend (
bool) – Whether to show a cluster legend.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_decision_boundaries(X, result, ax=None, title=None, resolution=None, show_points=None, show_contour_lines=None, show_centers=None, show_regions=None, x_lim=None, y_lim=None, boundary_color=None)[source]¶
Plot decision boundaries (and optionally regions, data points, centers).
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).result (
ClusterResult) – Clustering result.ax (
Axes|None) – Matplotlib axes (created ifNone).resolution (
int|None) – Grid resolution for boundary computation. Defaults toself.style.decision_boundary_resolution.show_points (
bool|None) – Overlay data points. Defaults to style setting.show_contour_lines (
bool|None) – Draw boundary contour lines. Defaults to style setting.show_centers (
bool|None) – Show center markers. Defaults to style setting.show_regions (
bool|None) – Fill decision regions with colour. Defaults to style setting.boundary_color (
str|None) – Override colour for boundary lines.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_density_contours(X, ax=None, title=None, levels=20, bandwidth=0.2)[source]¶
Plot KDE density contours of the data.
- Parameters:
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_density_with_boundaries(X, result, ax=None, title=None, resolution=300, kde_levels=20, kde_bandwidth=0.2, show_centers=True, x_lim=None, y_lim=None)[source]¶
Overlay KDE density contours with decision boundary lines.
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).result (
ClusterResult) – Clustering result.ax (
Axes|None) – Matplotlib axes (created ifNone).resolution (
int) – Grid resolution for boundary computation.kde_levels (
int) – Number of KDE contour levels.kde_bandwidth (
float) – KDE bandwidth parameter.show_centers (
bool) – Whether to overlay center markers.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_expectile_curves(center, index_vector, cost_levels=None, ax=None, title=None, show_index_arrow=True, curve_color=None, extent=3.0, resolution=300)[source]¶
Plot level curves of the expectile loss around a single center.
- Parameters:
center (
ndarray) – Center point of shape(2,).index_vector (
ndarray) – Index vector of shape(2,).cost_levels (
ndarray|None) – Loss values at which to draw contours.ax (
Axes|None) – Matplotlib axes (created ifNone).show_index_arrow (
bool) – Whether to draw the index vector arrow.curve_color (
str|None) – Override colour for contour lines.extent (
float) – Half-width of the plotting window aroundcenter.resolution (
int) – Grid resolution.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- plot_loss_comparison(loss_functions, x_range=(-3, 3), n_points=300, ax=None, title=None, show_legend=True)[source]¶
Plot one-dimensional loss function comparisons.
- Parameters:
loss_functions (
list[tuple[str,Callable[[ndarray],ndarray]]]) – List of(name, callable)pairs.x_range (
tuple[float,float]) – Domain(x_min, x_max)for the plot.n_points (
int) – Number of evaluation points.ax (
Axes|None) – Matplotlib axes (created ifNone).show_legend (
bool) – Whether to display a legend.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the plot.
- create_comparison_figure(X, results, plot_type='assignments', nrows=None, ncols=None, figsize=None, align_labels=True, **plot_kwargs)[source]¶
Create a multi-panel comparison figure.
- Parameters:
X (
ndarray) – Data array of shape(n_samples, 2).results (
list[tuple[str,ClusterResult]]) – List of(name, ClusterResult)pairs for each panel.plot_type (
str) – One of"assignments","boundaries", or"density".nrows (
int|None) – Number of subplot rows (inferred ifNone).ncols (
int|None) – Number of subplot columns (inferred ifNone).figsize (
tuple[float,float] |None) – Override figure size.align_labels (
bool) – Whether to align cluster labels across panels via permutation matching.**plot_kwargs (
Any) – Extra keyword arguments forwarded to the per-panel plot method.
- Return type:
Figure- Returns:
The matplotlib
Figurecontaining the comparison.
- class geomexp.visualization.PlotStyle(figsize=(3.5, 3.5), dpi=300, point_size=1.5, center_size=15, center_linewidth=0.8, alpha_data=0.7, alpha_contour=0.15, color_palette=None, center_color='black', center_marker='o', arrow_color='black', arrow_linewidth=0.8, arrow_head_width=0.15, arrow_head_length=0.2, arrow_scale=1, contour_color='black', contour_linewidth=0.5, contour_alpha=0.9, curve_linewidth=0.8, curve_alpha=0.7, kde_color='gray', kde_linewidth=0.4, kde_alpha=0.6, loss_linewidth=1.0, decision_boundary_resolution=300, decision_boundary_show_points=True, decision_boundary_show_contour_lines=True, decision_boundary_show_centers=True, decision_boundary_show_regions=True, decision_boundary_color=None, axis_linewidth=0.6, grid_alpha=0.15, grid_linewidth=0.3, fontsize=9, use_latex=True)[source]¶
Bases:
objectCentral styling configuration for all cluster visualisations.
Every plot produced by
ClusterVisualizerreads its visual parameters from this object, ensuring that all figures in a study share a uniform appearance. Construct aPlotStyleinstance first, then pass it toClusterVisualizer(style).- Parameters:
dpi (int)
point_size (float)
center_size (float)
center_linewidth (float)
alpha_data (float)
alpha_contour (float)
center_color (str)
center_marker (str)
arrow_color (str)
arrow_linewidth (float)
arrow_head_width (float)
arrow_head_length (float)
arrow_scale (float)
contour_color (str)
contour_linewidth (float)
contour_alpha (float)
curve_linewidth (float)
curve_alpha (float)
kde_color (str)
kde_linewidth (float)
kde_alpha (float)
loss_linewidth (float)
decision_boundary_resolution (int)
decision_boundary_show_points (bool)
decision_boundary_show_contour_lines (bool)
decision_boundary_show_centers (bool)
decision_boundary_show_regions (bool)
decision_boundary_color (str | None)
axis_linewidth (float)
grid_alpha (float)
grid_linewidth (float)
fontsize (float)
use_latex (bool)
- figsize¶
Default figure size
(width, height)in inches.
- dpi¶
Resolution in dots per inch.
- point_size¶
Scatter point size for data points.
- center_size¶
Scatter point size for cluster centers.
- center_linewidth¶
Edge line width for center markers.
- alpha_data¶
Opacity of data points.
- alpha_contour¶
Opacity of coloured decision regions.
- color_palette¶
List of hex colour strings cycled over clusters.
- center_color¶
Colour of center markers.
- center_marker¶
Marker shape for centers.
- arrow_color¶
Colour of index vector arrows.
- arrow_linewidth¶
Line width of index vector arrows.
- arrow_head_width¶
Head width of index vector arrows.
- arrow_head_length¶
Head length of index vector arrows.
- arrow_scale¶
Multiplicative scaling applied to index vector arrows for visibility.
- contour_color¶
Colour of decision boundary lines.
- contour_linewidth¶
Line width of decision boundary contours.
- contour_alpha¶
Opacity of decision boundary contour lines.
- curve_linewidth¶
Line width of expectile level-set contours.
- curve_alpha¶
Opacity of expectile level-set contour lines.
- kde_color¶
Colour of KDE density contour lines.
- kde_linewidth¶
Line width of KDE density contour lines.
- kde_alpha¶
Opacity of KDE density contour lines.
- loss_linewidth¶
Line width of loss function curves.
- decision_boundary_resolution¶
Grid resolution for boundary computation.
- decision_boundary_show_points¶
Whether to overlay data points on boundary plots.
- decision_boundary_show_contour_lines¶
Whether to draw boundary contour lines.
- decision_boundary_show_centers¶
Whether to show center markers on boundary plots.
- decision_boundary_show_regions¶
Whether to fill decision regions with colour.
- decision_boundary_color¶
Override colour for boundary lines (
Noneuses palette).
- axis_linewidth¶
Width of axis spines and tick marks.
- grid_alpha¶
Opacity of grid lines.
- grid_linewidth¶
Width of grid lines.
- fontsize¶
Base font size for labels and titles.
- use_latex¶
Whether to enable LaTeX rendering via
text.usetex.