plot_utils
anomaly_match_ui.utils.plot_utils
¶
Plotting utilities extracted from UI screens for reuse and testability.
render_histogram_png(counts, edges, bar_color, *, figsize=(3.0, 2.0), dpi=100, xlabel='Score', title=None, log_y=False)
¶
Render a histogram as PNG bytes.
Used for the linear-x score histogram; the source-size distribution has its
own overlay renderer (:func:render_size_stratification_png).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
ndarray
|
Bin counts from a histogram. |
required |
edges
|
ndarray
|
Bin edges (length |
required |
bar_color
|
str
|
CSS colour string for the bars. |
required |
figsize
|
tuple[float, float]
|
Figure size in inches. |
(3.0, 2.0)
|
dpi
|
int
|
Output resolution. |
100
|
xlabel
|
str
|
X-axis label (defaults to |
'Score'
|
title
|
str | None
|
Optional axes title. |
None
|
log_y
|
bool
|
Use a logarithmic y-axis — the score distribution is sharply peaked, so a linear count axis buries the rare high-score tail (where the anomalies live) in a flat line at the bottom. |
False
|
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as bytes. |
Source code in anomaly_match_ui/utils/plot_utils.py
render_size_stratification_png(edges, population_counts, sampled_counts, *, population_color, sampled_color, unit='pixel', stratified=False, figsize=(3.0, 2.0), dpi=100)
¶
Overlay the sampled unlabeled pool's sizes on the tile-population sizes.
The filled bars are the candidate population (every source in the drawn tiles); the step line is the sampled unlabeled pool. Both are normalised to a per-bin fraction so their shapes are comparable despite the population dwarfing the sample in absolute count — with stratification on, the sampled line should be visibly flatter (~uniform in log size) than the small-skewed population, which is the visual confirmation that stratification worked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
ndarray
|
Shared log-spaced bin edges (length |
required |
population_counts
|
ndarray
|
Per-bin counts of the tile population. |
required |
sampled_counts
|
ndarray
|
Per-bin counts of the sampled unlabeled pool. |
required |
population_color
|
str
|
CSS colour for the population bars. |
required |
sampled_color
|
str
|
CSS colour for the sampled step line. |
required |
unit
|
str
|
Diameter unit for the x-axis label ( |
'pixel'
|
stratified
|
bool
|
Whether size stratification was applied (annotates the title). |
False
|
figsize
|
tuple[float, float]
|
Figure size in inches. |
(3.0, 2.0)
|
dpi
|
int
|
Output resolution. |
100
|
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as bytes. |