plot_function
Network visualization orchestration module.
Provides the main plotting interface for pathpyG networks with automatic backend selection and plot type detection. Serves as the unified entry point for all visualization functionality across different backends and graph types.
Key Features
- Multi-backend support (matplotlib, TikZ, d3.js, manim)
- Automatic plot type detection (static vs temporal)
- File format-based backend inference
- Unified plotting interface for all graph types
Supported Backends
- matplotlib: PNG, JPG plots for static visualization
- TikZ: PDF, SVG, TEX for publication-quality vector graphics
- d3.js: HTML for interactive web visualization
- manim: MP4, GIF for animated temporal networks
Examples:
Plot a static network with the matplotlib backend and save it as network.png:
>>> import pathpyG as pp
>>> g = pp.Graph.from_edge_list([('a', 'b'), ('b', 'c')])
>>> pp.plot(g, filename='network.png')

Plot a temporal network with the default d3.js backend:
>>> import pathpyG as pp
>>> tg = pp.TemporalGraph.from_edge_list([('a', 'b', 1), ('b', 'c', 2), ('a', 'c', 3)])
>>> pp.plot(tg)
```
Backend Selection
Backends are auto-selected from file extensions or can be explicitly
specified via the backend parameter.
Backends
¶
Bases: str, enum.Enum
Enumeration of supported visualization backends.
Defines the available backend engines for network visualization, each optimized for different output formats and use cases.
Source code in src/pathpyG/visualisations/plot_function.py
is_backend
staticmethod
¶
Check if string is a valid backend identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Backend name to validate |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if backend is supported, False otherwise |
Source code in src/pathpyG/visualisations/plot_function.py
plot
¶
Make plot of pathpyG objects.
Creates and displays a plot for a given pathpyG object. This function can
generate different types of network plots based on the nature of the input
data and specified plot kind.
The function dynamically determines the plot type if not explicitly
provided, based on the input data type. It supports static network plots
for Graph objects, temporal network plots for TemporalGraph objects,
and potentially other types if specified in kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
pathpyG.core.graph.Graph
|
A |
required |
kind
|
typing.Optional[str]
|
A string keyword defining the type of plot to generate. Options include: 'static', and 'temporal'. |
None
|
show_labels
|
Whether to display node labels (None uses graph.mapping.has_ids) |
None
|
|
**kwargs
|
typing.Any
|
Backend-specific plotting parameters including: filename: Output file path (triggers backend auto-selection); backend: Explicit backend choice; layout: Layout algorithm name; style: Various styling parameters (colors, sizes, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
pathpyG.visualisations.plot_backend.PlotBackend
|
Configured backend instance ready for display or saving |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If graph type cannot be auto-detected for plotting |
KeyError
|
If specified backend is not supported |
ImportError
|
If required backend cannot be loaded |
Examples:
This will create a static network plot of the graph and save it to 'graph.png'.
>>> import pathpyG as pp
>>> graph = pp.Graph.from_edge_list([["a", "b"], ["b", "c"], ["a", "c"]])
>>> pp.plot(graph, kind="static", filename="graph.png")

Note
- If a 'filename' is provided in
kwargs, the plot will be saved to that file. Otherwise, it will be displayed usingplt.show(). - The function's behavior and the available options in
kwargsmight change based on the type of plot being generated.
Backend Auto-Selection
When filename is provided, backend is inferred from extension:
| Extension | Backend | Best For |
|---|---|---|
| .png, .jpg | matplotlib | Quick visualization |
| .pdf, .svg, .tex | tikz | Publication quality |
| .html | d3js | Interactive exploration |
| .mp4, .gif | manim | Animated sequences |
Source code in src/pathpyG/visualisations/plot_function.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |