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: object

Render FeynmanDiagram objects 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. Nonedefault_style().

  • external_label_fn (LabelCallable | None) – Optional callable fn(node_id, node_attrs) -> str | None invoked per external node. Returning None falls 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). Overrides style.label_format when 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 style to the constructor, any monkey-patches to the legacy class attribute PROP_STYLES are folded in for backward compatibility. When the user did pass a style, it is respected verbatim.

property label_format: str
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 size self.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’s title_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:

Axes

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. False restores per-panel legends.

  • wspace (float) – Optional subplot spacing passed to Figure.subplots_adjust after tight_layout. hspace=None uses a compact automatic value and relaxes it if rendered rows would overlap.

  • hspace (float | None) – Optional subplot spacing passed to Figure.subplots_adjust after tight_layout. hspace=None uses a compact automatic value and relaxes it if rendered rows would overlap.

  • show (bool) – If True, call plt.show() after building the figure. Default False — callers that savefig should 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 when show=True).

Return type:

Figure