Visualization¶
synamine supports two kinds of visualization: model rendering (Graphviz-based) and statistics charts (Matplotlib-based).
Prerequisites
Install the visualization extras: pip install "synamine[viz]"
For DFG, Petri Net, and Process Tree rendering, you also need the Graphviz system binary.
Saving model visualizations¶
Use save_visualization to save any model to file. The format is inferred from the extension (.png, .svg, .pdf):
import synamine
log = synamine.read_xes("events.xes")
dfg = synamine.discover_dfg(log)
synamine.save_visualization(dfg, "dfg.png")
pn = synamine.discover_petri_net(log, algorithm="alpha")
synamine.save_visualization(pn, "petri_net.svg")
pt = synamine.discover_process_tree(log)
synamine.save_visualization(pt, "process_tree.pdf")
trie = synamine.discover_variant_trie(log)
synamine.save_visualization(trie, "trie.png")
Interactive viewing¶
Open a model in your system's default viewer:
synamine.view_dfg(dfg)
synamine.view_petri_net(pn)
synamine.view_process_tree(pt)
synamine.view_variant_trie(trie)
Variant Trie options¶
Label strategy¶
Controls how node labels are rendered when the tree is dense:
| Value | Behavior |
|---|---|
"auto" (default) |
Boxes sized to fit the full activity label. Font size scales with tree density. |
"truncate" |
Long labels are trimmed with an ellipsis (...) to fit a maximum box width. |
"hide" |
Nodes with < 5% frequency show only their count (e.g. (12)) instead of the activity name. |
Percentage reference¶
Controls what edge percentages are relative to:
| Value | Behavior |
|---|---|
"absolute" (default) |
Percentage of all traces (root count). |
"relative" |
Percentage of the parent node's count (branching probability). |
Examples¶
trie = synamine.discover_variant_trie(log)
# Default: full labels, absolute percentages
synamine.save_visualization(trie, "trie.png")
# Truncate long labels, show branching probabilities
synamine.save_visualization(
trie, "trie.png",
label_strategy="truncate",
pct_reference="relative",
)
# Hide rare nodes, keep absolute percentages
synamine.save_visualization(trie, "trie.svg", label_strategy="hide")
# Interactive viewer with options
synamine.view_variant_trie(
trie,
label_strategy="hide",
pct_reference="relative",
)
Pruning¶
Remove low-frequency branches before visualization:
trie = synamine.discover_variant_trie(log)
pruned = trie.prune(min_count=10) # keep only variants with >= 10 traces
synamine.save_visualization(pruned, "trie_pruned.png")
Statistics charts¶
All chart functions follow the pattern plot_*(log, *, path=None) -> Figure | None:
- With
path: saves the chart to file and returnsNone - Without
path: returns a matplotlibFigurefor customization
Available charts¶
| Function | Chart Type |
|---|---|
plot_activity_frequencies(log) |
Horizontal bar chart |
plot_case_durations(log) |
Duration histogram (hours) |
plot_case_lengths(log) |
Case length histogram |
plot_start_end_activities(log) |
Grouped bar chart (start vs end) |
plot_variant_frequencies(log, top_k=10) |
Top-k variant bar chart |
plot_cases_over_time(log, freq="W") |
Case arrivals line chart |
Save to file¶
synamine.plot_activity_frequencies(log, path="activities.png")
synamine.plot_case_durations(log, path="durations.png")
synamine.plot_case_lengths(log, path="lengths.png")
synamine.plot_start_end_activities(log, path="start_end.png")
synamine.plot_variant_frequencies(log, path="variants.png", top_k=10)
synamine.plot_cases_over_time(log, path="cases_over_time.png", freq="W")
Get Figure for customization¶
fig = synamine.plot_case_durations(log)
fig.axes[0].set_title("My Custom Title")
fig.savefig("custom.png")
This is especially useful in Jupyter notebooks where you can display figures inline.