backend
TikZ/LaTeX Backend for High-Quality Network Visualizations.
This backend generates publication-ready vector graphics using LaTeX's TikZ package. It provides precise control over visual elements and produces scalable output suitable for academic papers, presentations, and professional documentation.
Backend Capabilities
- Static networks only - Temporal networks not supported
- Vector output - SVG, PDF, and raw TeX formats
- LaTeX compilation - Automatic document generation and compilation
- Custom styling - Full control over colors, sizes, and layouts
The backend handles the complete workflow from graph data to compiled output, including template processing, LaTeX compilation, and format conversion.
Workflow Overview¶
graph LR
A[Graph Data] --> B[TikZ Template]
B --> C[LaTeX Document]
C --> D[Compilation]
D --> E[PDF Output]
D --> F[DVI Output]
F --> H[Conversion]
H --> I[SVG Output]
C --> G[TeX Output]
Performance Considerations
- Compilation time scales with network complexity
- Large networks (>500 nodes) may require significant processing time
- Consider
matplotlibbackend for rapid prototyping of complex networks
TikzBackend
¶
Bases: pathpyG.visualisations.plot_backend.PlotBackend
TikZ/LaTeX Backend for Publication-Quality Network Graphics.
Generates high-quality vector graphics using LaTeX's TikZ package.
The backend mainly uses the tikz-network
package to create detailed and customizable visualizations. This backend
is optimized for static networks and provides publication-ready output with
precise control over visual elements.
Supported Operations
- Formats: SVG, PDF, TeX
- Networks: Static graphs only
- Styling: Full customization support
- Layouts: All pathpyG layout algorithms
The backend automatically handles LaTeX compilation, temporary file management, and format conversion to deliver clean, scalable graphics suitable for academic publications and professional presentations.
Attributes:
| Name | Type | Description |
|---|---|---|
plot |
The PathPyPlot instance containing graph data and configuration |
|
show_labels |
Whether to display node labels in the output |
|
_kind |
Type of plot being processed (for now only "static" supported) |
Example
# The backend is typically used via pp.plot()
import pathpyG as pp
g = pp.Graph.from_edge_list([("A", "B"), ("B", "C")])
pp.plot(g, backend="tikz")
Source code in src/pathpyG/visualisations/_tikz/backend.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
__init__
¶
Initialize the TikZ backend with plot data and configuration.
Sets up the backend to process the provided plot data and validates that the plot type is supported by the TikZ backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot
|
pathpyG.visualisations.pathpy_plot.PathPyPlot
|
PathPyPlot instance containing graph data, layout, and styling |
required |
show_labels
|
bool
|
Whether to display node labels in the generated output |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the plot type is not supported by the TikZ backend |
Note
Currently only static NetworkPlot instances are supported. Temporal networks require, e.g. the manim backend instead.
Source code in src/pathpyG/visualisations/_tikz/backend.py
compile_pdf
¶
Compile LaTeX source to PDF format using pdflatex.
Generates a high-quality PDF document suitable for printing and publication. Uses latexmk with PDF mode for robust compilation and automatic dependency handling.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
(pdf_file_path, temp_directory_path) for the compiled PDF |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If LaTeX compilation fails or pdflatex is not available |
Note
Requires latexmk and a PDF-capable LaTeX engine (pdflatex, xelatex, etc.).
Source code in src/pathpyG/visualisations/_tikz/backend.py
compile_svg
¶
Compile LaTeX source to SVG format using the LaTeX toolchain.
Performs a complete compilation workflow: TeX → DVI → SVG conversion. Uses latexmk for robust LaTeX compilation and dvisvgm for high-quality SVG conversion with proper text rendering.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
(svg_file_path, temp_directory_path) for the compiled SVG |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If LaTeX compilation fails or required tools are missing |
Compilation Steps
- Generate temporary directory and save TeX source
- Run latexmk to compile TeX → DVI
- Use dvisvgm to convert DVI → SVG
- Return paths for file access and cleanup
Note
Both latexmk and dvisvgm must be available in the system PATH.
Source code in src/pathpyG/visualisations/_tikz/backend.py
save
¶
Save the network visualization to a file in the specified format.
Automatically detects the output format from the file extension and performs the necessary compilation steps. Supports TeX (raw LaTeX), PDF (compiled document), and SVG (vector graphics) formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output file path with extension (.tex, .pdf, or .svg) |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the file extension is not supported |
Note
PDF and SVG compilation requires LaTeX toolchain installation. The method handles temporary file creation and cleanup automatically.
Source code in src/pathpyG/visualisations/_tikz/backend.py
show
¶
Display the network visualization in the current environment.
Compiles the network to SVG format and displays it either inline (in Jupyter notebooks) or opens it in the default web browser. The display method is automatically chosen based on the environment.
The method creates temporary files for compilation and cleans them up automatically after display.
Environment Detection
- Interactive (Jupyter): Displays SVG inline using IPython.display
- Non-interactive: Opens SVG file in default web browser
Note
Requires LaTeX toolchain with TikZ and dvisvgm for SVG compilation. Temporary files are automatically cleaned up after a brief delay.
Source code in src/pathpyG/visualisations/_tikz/backend.py
to_tex
¶
Generate complete LaTeX document with TikZ network visualization.
Combines the network data with a LaTeX template to create a complete document ready for compilation. The template includes all necessary packages, document setup, and TikZ drawing commands.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Complete LaTeX document source code |
Process
- Load template - Retrieves the appropriate template for the plot type
- Generate TikZ - Converts network data to TikZ drawing commands
- Template substitution - Fills template variables with graph data
- Return final string - Complete LaTeX document ready for compilation
Template Variables
$classoptions: LaTeX class options$width,$height: Document dimensions$margin: Margin around the drawing area$tikz: TikZ drawing commands for nodes and edges
Note
The generated document is self-contained and includes all necessary TikZ packages and configuration for network visualization.
Source code in src/pathpyG/visualisations/_tikz/backend.py
to_tikz
¶
Generate TikZ drawing commands for the network visualization.
Converts the processed graph data (nodes, edges, layout) into TikZ-specific drawing commands. Handles node positioning, styling, edge routing, and label placement according to the configured visualization parameters.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
TikZ drawing commands ready for inclusion in LaTeX document |
Generated Elements
- Node commands -
\Vertexwith labels, positions, colors, and sizes - Edge commands -
\Edgewith styling and optional curvature
Note
The output assumes the tikz-network package is loaded in the template. Coordinates are assumed to be normalized to [0, 1] range and scaled according to the specified document dimensions.
Source code in src/pathpyG/visualisations/_tikz/backend.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |