Skip to content

ergminer.vis

ergminer.save_vis_erg(erg, file_path, show_probabilities=True, show_distributions=True, show_guards=True, title=None, figsize=(18, 12))

Render erg and save it to file_path.

Parameters:

Name Type Description Default
erg 'ERG'

The ERG object to visualise.

required
file_path str

Destination file path (e.g. 'output/erg.png').

required
show_probabilities bool

Annotate arcs with routing probabilities.

True
show_distributions bool

Annotate arcs with delay distributions.

True
show_guards bool

Show guard conditions on arcs.

True
title Optional[str]

Optional title for the plot.

None
figsize tuple

Matplotlib figure size (width, height) in inches.

(18, 12)
Source code in src\ergminer\vis.py
def save_vis_erg(
    erg: 'ERG',
    file_path: str,
    show_probabilities: bool = True,
    show_distributions: bool = True,
    show_guards: bool = True,
    title: Optional[str] = None,
    figsize: tuple = (18, 12),
) -> None:
    """Render *erg* and save it to *file_path*.

    Args:
        erg:                The ``ERG`` object to visualise.
        file_path:          Destination file path (e.g. ``'output/erg.png'``).
        show_probabilities: Annotate arcs with routing probabilities.
        show_distributions: Annotate arcs with delay distributions.
        show_guards:        Show guard conditions on arcs.
        title:              Optional title for the plot.
        figsize:            Matplotlib figure size ``(width, height)`` in inches.
    """
    _check_plotter()
    from pathlib import Path
    Path(file_path).parent.mkdir(parents=True, exist_ok=True)
    _plot_erg(
        erg,
        figsize=figsize,
        save_path=file_path,
        show_probabilities=show_probabilities,
        show_distributions=show_distributions,
        show_guards=show_guards,
        title=title,
        verbose=True,
    )

ergminer.view_erg(erg, show_probabilities=True, show_distributions=True, show_guards=True, title=None, format='png')

Render erg and open it in the OS default image viewer.

Creates a temporary file, renders the ERG to it, then opens it with the system default application for that file type.

Parameters:

Name Type Description Default
erg 'ERG'

The ERG object to visualise.

required
show_probabilities bool

Annotate arcs with routing probabilities.

True
show_distributions bool

Annotate arcs with delay distributions.

True
show_guards bool

Show guard conditions on arcs.

True
title Optional[str]

Optional title for the plot.

None
format str

Image format ('png', 'svg', etc.).

'png'
Source code in src\ergminer\vis.py
def view_erg(
    erg: 'ERG',
    show_probabilities: bool = True,
    show_distributions: bool = True,
    show_guards: bool = True,
    title: Optional[str] = None,
    format: str = 'png',
) -> None:
    """Render *erg* and open it in the OS default image viewer.

    Creates a temporary file, renders the ERG to it, then opens it with the
    system default application for that file type.

    Args:
        erg:                The ``ERG`` object to visualise.
        show_probabilities: Annotate arcs with routing probabilities.
        show_distributions: Annotate arcs with delay distributions.
        show_guards:        Show guard conditions on arcs.
        title:              Optional title for the plot.
        format:             Image format (``'png'``, ``'svg'``, etc.).
    """
    _check_plotter()

    with tempfile.NamedTemporaryFile(
        suffix=f'.{format}', delete=False
    ) as tmp:
        tmp_path = tmp.name

    try:
        _plot_erg(
            erg,
            save_path=tmp_path,
            show_probabilities=show_probabilities,
            show_distributions=show_distributions,
            show_guards=show_guards,
            title=title,
            verbose=False,
        )
        _open_file(tmp_path)
    except Exception:
        if os.path.exists(tmp_path):
            os.remove(tmp_path)
        raise