sft_wick.drawing — Diagram Rendering¶
Matplotlib rendering for FeynmanDiagram objects.
Visual conventions are now controlled by a
RenderStyle instance: colours,
linestyles, marker sizes, fonts, layout parameters, and label
formatting are all configurable. See sft_wick.render_style
for the available presets (default / publication / grayscale /
minimal) and sft_wick.render_labels for the label
override hooks.
The constructor remains backward-compatible — calling
DiagramRenderer(figsize=(8, 6)) keeps working with the
default_style preset.
For a LaTeX-native alternative, see
sft_wick.drawing_tikz.TikzRenderer.
- class sft_wick.drawing.DiagramRenderer(figsize=(6, 5), style=None, external_label_fn=None, vertex_label_fn=None, label_format=None)[source]¶
Bases:
objectRender
FeynmanDiagramobjects with matplotlib.- Parameters:
figsize (tuple[float, float]) – Figure size in inches for the single-diagram entry point and the per-cell size for
draw_all.style (RenderStyle | None) – Visual style.
None→default_style().external_label_fn (LabelCallable | None) – Optional callable
fn(node_id, node_attrs) -> str | Noneinvoked per external node. ReturningNonefalls through to the built-in formatter.vertex_label_fn (LabelCallable | None) – Same shape, for interaction vertices.
label_format (str | None) – Default external-label format (
LABEL_COMPACT/LABEL_FULL/LABEL_TIME_F). Overridesstyle.label_formatwhen supplied explicitly.
- PROP_STYLES: dict[str, dict[str, Any]] = {'C': {'color': '#2166ac', 'linestyle': '-', 'linewidth': 2.0}, 'R': {'color': '#d6604d', 'linestyle': '--', 'linewidth': 2.0}}¶
- property style: RenderStyle¶
The active
RenderStyle.When the user did not pass a
styleto the constructor, any monkey-patches to the legacy class attributePROP_STYLESare folded in for backward compatibility. When the user did pass astyle, it is respected verbatim.
- draw(diagram, ax=None, title='', title_kwargs=None, external_labels=None, vertex_labels=None, positions=None, show_legend=None)[source]¶
Draw a single Feynman diagram on a matplotlib axes.
- Parameters:
diagram (FeynmanDiagram) – The diagram to render.
ax (Axes | None) – Existing axes to draw on;
None→ a new figure of sizeself.figsize.title (str) – Per-axes title. Empty string → use
diagram.summary().title_kwargs (Mapping[str, Any] | None) – Extra kwargs passed to
ax.set_title(overrides the style’stitle_fontsize).external_labels (Mapping[str, str] | None) – Map
{node_id: label}overriding specific external-vertex labels.vertex_labels (Mapping[str, str] | None) – Same shape, for interaction vertices.
positions (Mapping[str, tuple[float, float]] | None) – Map
{node_id: (x, y)}pinning specific node coordinates and skipping spring layout for them.show_legend (bool | None) – Override
style.show_legend.
- Return type:
- draw_all(diagrams, ncols=3, suptitle='', suptitle_kwargs=None, subtitle_fn=None, multiplicities=None, shared_legend=True, wspace=0.04, hspace=None, show=False, external_labels=None)[source]¶
Draw a grid of Feynman diagrams.
- Parameters:
diagrams (list[FeynmanDiagram]) – Diagrams to lay out, one per subplot.
ncols (int) – Maximum columns (clipped to
len(diagrams)).suptitle (str) – Figure-level title; pass
""to skip.suptitle_kwargs (Mapping[str, Any] | None) – Extra kwargs forwarded to
fig.suptitle.subtitle_fn (Callable[[int, FeynmanDiagram, int], str] | None) – Per-subplot title formatter
fn(index, diagram, multiplicity) -> str.None→"#i: <summary> [xN]".multiplicities (Sequence[int] | None) – Optional per-diagram multiplicities (for default subtitles).
shared_legend (bool) – If
True(default), suppress per-panel legends and draw one figure-level legend for all propagator kinds present in the grid.Falserestores per-panel legends.wspace (float) – Optional subplot spacing passed to
Figure.subplots_adjustaftertight_layout.hspace=Noneuses a compact automatic value and relaxes it if rendered rows would overlap.hspace (float | None) – Optional subplot spacing passed to
Figure.subplots_adjustaftertight_layout.hspace=Noneuses a compact automatic value and relaxes it if rendered rows would overlap.show (bool) – If
True, callplt.show()after building the figure. DefaultFalse— callers thatsavefigshould leave this off.external_labels (Mapping[int, Mapping[str, str]] | None) – Optional map keyed by subplot index whose values are
{node_id: label}overrides for that subplot.
- Returns:
The matplotlib
Figure(always returned, even whenshow=True).- Return type: