ClusterBarChart¶
Clustered line chart for array-like fields (e.g. singular value spectra). For
each parameter, the array field is binned into num_bins histogram counts over
the global value range; parameters are grouped by the group_by metadata keys,
aggregated (mean, and std when draw_statistics is set) across the parameters
in each group, and drawn as one lines+markers trace per group.
Class: diffract.viz.plots.cluster.ClusterBarChart (also
diffract.viz.plots.ClusterBarChart).
Basic usage¶
from diffract.viz.plots.cluster import ClusterBarChart
with session:
plot = ClusterBarChart(field="esd", group_by=["model_id"])
fig = session.viz.draw(plot=plot)
Unlike most plots, ClusterBarChart takes its field as a plain string
(field="esd"), not a FieldRef — the field must resolve to array-like
values, and group_by / color_by / dash_by / marker_by name metadata
keys directly.
Example: Compare spectra across models¶
from diffract.viz.plots.cluster import ClusterBarChart
with session:
fig = session.viz.draw(
plot=ClusterBarChart(
field="esd",
group_by=["model_id"],
num_bins=30,
binning="exponential",
color_by="model_id",
legend_format="{model_id}",
)
)
Parameters¶
Field (required, keyword-only)¶
Parameter |
Type |
Description |
|---|---|---|
|
|
Array-like field to bin (e.g. |
Grouping¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Metadata keys that define one trace per distinct combination |
|
|
|
Extra key whose values are averaged out within each group |
Parameter/model filtering¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Restrict to these parameter UIDs |
|
|
|
Restrict to these parameter names ( |
|
|
|
Restrict to these parameter types |
|
|
|
Restrict to these model IDs |
These are applied via Session.filter(...) before fetching data, so the plot
carries its own filtering (useful in YAML configs).
Binning¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Number of histogram bins |
|
|
|
Bin edge spacing |
|
|
|
Left edge of the binning range (defaults to the data minimum) |
|
|
|
Right edge of the binning range (defaults to the data maximum) |
Statistics and trace styling¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Draw per-group std below zero as a dashed trace |
|
|
|
Plotly trace mode |
|
|
|
Metadata key mapped to line color |
|
|
|
Metadata key mapped to line dash |
|
|
|
Metadata key mapped to marker symbol |
Legend¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Format string over group keys, e.g. |
|
|
|
Subset of group keys to show as |
If neither is set, legend entries list all group keys as key=value pairs.
Common fields (from Plot)¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Figure title (defaults to |
|
|
|
Filter conditions |
Theming¶
Themes are not a constructor field. Pass a Theme when rendering:
from diffract.viz.styling import DARK_THEME
fig = session.viz.draw(plot=plot, theme=DARK_THEME)
YAML configuration¶
Adapted from notebooks/configs/plots/cluster_bar_charts/compare_checkpoints.yaml:
plot:
_target_: diffract.viz.plots.base.UpdateFigure
layout:
width: 1000
height: 480
yaxes:
title: "count per bin (mean over heads)"
type: log
dtick: 1
plot:
_target_: diffract.viz.plots.cluster.ClusterBarChart
field: weights_svals
title: "Singular value spectrum: 16k vs 128k pre-train steps"
parameter_names:
- re:.*(q|k|v|o)_proj_head.*
group_by: [model_id]
color_by: model_id
dash_by: model_id
legend_format: "{model_id}"
num_bins: 40
left_bound: 0.0
binning: linear
draw_statistics: false
How it works¶
Applies the plot-level parameter/model filter (if any) via
Session.filter.Fetches the array field for every remaining parameter.
Computes shared bin edges over the global value range (
np.linspaceforlinear,np.geomspaceforexponential).Bins each parameter’s array into histogram counts.
Groups counts by the
group_bykeys (minusaggregate_by) and averages them within each group.Adds one
go.Scattertrace per group at the numeric bin centers (geometric means of the edges forexponentialbinning).
Notes¶
Bin centers are numeric, so the x axis stays quantitative — a
type: logaxis (e.g. viaUpdateFigure) positions the bins honestly.With
draw_statistics: true, each group’s std is drawn as a dashed trace mirrored below zero, with a horizontal reference line at zero.Entries missing any
group_bykey are skipped.
See also¶
Plot Types — Overview and the
UpdateFigurewrapperLine/Sparkline — A scalar field vs another field