Skip to content

ragraph.plot

RaGraph plotting module

Style

Style(
    convention: Optional[Convention] = None,
    boxsize: Optional[int] = None,
    config: Optional[Dict[str, Any]] = None,
    highlight_annotation: Optional[str] = None,
    highlight_color: Optional[str] = None,
    labels: Optional[
        Union[LabelsStyle, Dict[str, Any]]
    ] = None,
    layout: Optional[Union[Layout, Dict[str, Any]]] = None,
    palettes: Optional[Palettes] = None,
    piemap: Optional[
        Union[PieMapStyle, Dict[str, Any]]
    ] = None,
    tree: Optional[Union[TreeStyle, Dict[str, Any]]] = None,
    legend: Optional[
        Union[LegendStyle, Dict[str, Any]]
    ] = None,
    show_legend: Optional[bool] = None,
    chord: Optional[
        Union[ChordStyle, Dict[str, Any]]
    ] = None,
    row_col_numbers: Optional[bool] = None,
    xstep: Optional[str] = None,
    ystep: Optional[str] = None,
)

Bases: Mapping

RaGraph plot style mapping.

Parameters:

Name Type Description Default
convention Optional[Convention]

Convention to use when drawing edges.

None
boxsize Optional[int]

Size in pixels per row or column.

None
config Optional[Dict[str, Any]]

Plotly Figure.show() config.

None
highlight_annotation Optional[str]

Annotation key of instances that should be highlighted. Value should be True-ish. Set key to None to disable.

None
highlight_color Optional[str]

Default color to use for highlights.

None
labels Optional[Union[LabelsStyle, Dict[str, Any]]]

Labels plot style.

None
layout Optional[Union[Layout, Dict[str, Any]]]

Layout options.

None
palettes Optional[Palettes]

Plot palettes options.

None
piemap Optional[Union[PieMapStyle, Dict[str, Any]]]

Piechart map plot style.

None
tree Optional[Union[TreeStyle, Dict[str, Any]]]

Tree plot style.

None
legend Optional[Union[LegendStyle, Dict[str, Any]]]

Legend plot style.

None
show_legend Optional[bool]

Bool to display legend.

None
chord Optional[Union[ChordStyle, Dict[str, Any]]]

Chord plot style.

None
row_col_numbers Optional[bool]

Bool to display row and column numbers.

None
xstep Optional[str]

Axis increment per row or column in plots (usually 1).

None
ystep Optional[str]

Axis increment per row or column in plots (usually 1).

None
Source code in ragraph/plot/generic.py
def __init__(
    self,
    convention: Optional[Convention] = None,
    boxsize: Optional[int] = None,
    config: Optional[Dict[str, Any]] = None,
    highlight_annotation: Optional[str] = None,
    highlight_color: Optional[str] = None,
    labels: Optional[Union[LabelsStyle, Dict[str, Any]]] = None,
    layout: Optional[Union[go.Layout, Dict[str, Any]]] = None,
    palettes: Optional[Palettes] = None,
    piemap: Optional[Union[PieMapStyle, Dict[str, Any]]] = None,
    tree: Optional[Union[TreeStyle, Dict[str, Any]]] = None,
    legend: Optional[Union[LegendStyle, Dict[str, Any]]] = None,
    show_legend: Optional[bool] = None,
    chord: Optional[Union[ChordStyle, Dict[str, Any]]] = None,
    row_col_numbers: Optional[bool] = None,
    xstep: Optional[str] = None,
    ystep: Optional[str] = None,
):
    super().__init__(
        convention=convention,
        boxsize=boxsize,
        config=config,
        highlight_annotation=highlight_annotation,
        highlight_color=highlight_color,
        labels=labels,
        layout=layout,
        palettes=palettes,
        piemap=piemap,
        tree=tree,
        legend=legend,
        show_legend=show_legend,
        chord=chord,
        row_col_numbers=row_col_numbers,
        xstep=xstep,
        ystep=ystep,
    )

boxsize

boxsize() -> int

Size in pixels per row or column.

Source code in ragraph/plot/generic.py
@field
def boxsize(self) -> int:  # type: ignore
    """Size in pixels per row or column."""

chord

chord() -> ChordStyle

Chord plot style.

Source code in ragraph/plot/generic.py
@field
def chord(self) -> ChordStyle:  # type: ignore
    """Chord plot style."""

config

config() -> Dict[str, Any]

Plotly Figure.show() config.

Source code in ragraph/plot/generic.py
@field
def config(self) -> Dict[str, Any]:  # type: ignore
    """Plotly Figure.show() config."""

convention

convention() -> Convention

Convention to use when drawing edges.

Source code in ragraph/plot/generic.py
@field
def convention(self) -> Convention:  # type: ignore
    """Convention to use when drawing edges."""

highlight_annotation

highlight_annotation() -> Optional[str]

Annotation key of instances that should be highlighted. Value should be True-ish. Set key to None to disable.

Source code in ragraph/plot/generic.py
@field
def highlight_annotation(self) -> Optional[str]:  # type: ignore
    """Annotation key of instances that should be highlighted.
    Value should be True-ish. Set key to `None` to disable."""

highlight_color

highlight_color() -> str

Default color to use for highlights.

Source code in ragraph/plot/generic.py
@field
def highlight_color(self) -> str:  # type: ignore
    """Default color to use for highlights."""

labels

labels() -> LabelsStyle

Labels plot style.

Source code in ragraph/plot/generic.py
@field
def labels(self) -> LabelsStyle:  # type: ignore
    """Labels plot style."""

layout

layout() -> Layout

Layout options.

Source code in ragraph/plot/generic.py
@field
def layout(self) -> go.Layout:  # type: ignore
    """Layout options."""

legend

legend() -> LegendStyle

Legend plot style.

Source code in ragraph/plot/generic.py
@field
def legend(self) -> LegendStyle:  # type: ignore
    """Legend plot style."""

palettes

palettes() -> Palettes

Plot palettes options.

Source code in ragraph/plot/generic.py
@field
def palettes(self) -> Palettes:  # type: ignore
    """Plot palettes options."""

piemap

piemap() -> PieMapStyle

Piechart map plot style.

Source code in ragraph/plot/generic.py
@field
def piemap(self) -> PieMapStyle:  # type: ignore
    """Piechart map plot style."""

row_col_numbers

row_col_numbers() -> bool

Boolean to display row and column numbers.

Source code in ragraph/plot/generic.py
@field
def row_col_numbers(self) -> bool:  # type: ignore
    """Boolean to display row and column numbers."""

show_legend

show_legend() -> bool

Boolean to display a legend.

Source code in ragraph/plot/generic.py
@field
def show_legend(self) -> bool:  # type: ignore
    """Boolean to display a legend."""

tree

tree() -> TreeStyle

Tree plot style.

Source code in ragraph/plot/generic.py
@field
def tree(self) -> TreeStyle:  # type: ignore
    """Tree plot style."""

xstep

xstep() -> float

Axis increment per row or column in plots (usually 1).

Source code in ragraph/plot/generic.py
@field
def xstep(self) -> float:  # type: ignore
    """Axis increment per row or column in plots (usually 1)."""

ystep

ystep() -> float

Axis increment per row or column in plots (usually 1).

Source code in ragraph/plot/generic.py
@field
def ystep(self) -> float:  # type: ignore
    """Axis increment per row or column in plots (usually 1)."""

chord

1
2
3
4
5
6
7
8
chord(
    graph: Graph,
    nodes: Optional[Union[List[Node], List[str]]] = None,
    style: Optional[Style] = None,
    adj_kwargs: Optional[Dict[str, Any]] = None,
    symmetrize: bool = False,
    show: bool = False,
) -> Chord

Make a chord plot for the given nodes in a graph.

Parameters:

Name Type Description Default
graph Graph

Graph to create a chord plot for.

required
nodes Optional[Union[List[Node], List[str]]]

Nodes or node names to include in the chord plot. Defaults to leaf nodes.

None
style Optional[Style]

Plotting style.

None
adj_kwargs Optional[Dict[str, Any]] None
symmetrize bool

Whether to symmetrize the adjacency matrix.

False
show bool

Whether to show the resulting figure.

False

Returns:

Type Description
Chord

Chord plot using openchord.

Source code in ragraph/plot/components/chord.py
def chord(
    graph: Graph,
    nodes: Optional[Union[List[Node], List[str]]] = None,
    style: Optional[Style] = None,
    adj_kwargs: Optional[Dict[str, Any]] = None,
    symmetrize: bool = False,
    show: bool = False,
) -> ocd.Chord:
    """Make a chord plot for the given nodes in a graph.

    Arguments:
        graph: Graph to create a chord plot for.
        nodes: Nodes or node names to include in the chord plot. Defaults to leaf nodes.
        style: Plotting style.
        adj_kwargs: Additional arguments to [`ragraph.graph.Graph.get_adjacency_matrix`
            ][ragraph.graph.Graph.get_adjacency_matrix].
        symmetrize: Whether to symmetrize the adjacency matrix.
        show: Whether to show the resulting figure.

    Returns:
        Chord plot using openchord.
    """
    nodes = graph.leafs if nodes is None else nodes
    nodes = [n if isinstance(n, Node) else graph.node_dict[n] for n in nodes]
    labels = [n.name for n in nodes]

    adj_kwargs = dict() if adj_kwargs is None else adj_kwargs
    adj = graph.get_adjacency_matrix(nodes=nodes, **adj_kwargs)

    if symmetrize:
        dim = len(nodes)
        for row in range(dim):
            for col in range(row, dim):
                value = (adj[row][col] + adj[col][row]) / 2
                adj[row][col] = value
                adj[col][row] = value

    style: Style = Style() if style is None else style
    cs = style.chord
    fig = ocd.Chord(adj, labels, radius=cs.radius)
    fig.padding = (
        cs.fontsize * cs.fontfactor * max(len(x) for x in labels)
        if cs.padding is None
        else cs.padding
    )
    fig.gap_size = cs.gap_size
    fig.ribbon_gap = cs.ribbon_gap
    fig.ribbon_stiffness = cs.ribbon_stiffness
    fig.arc_thickness = cs.arc_thickness
    fig.bg_color = cs.bg_color
    fig.bg_transparency = cs.bg_transparency
    fig.font_size = cs.fontsize
    fig.font_family = cs.fontfamily

    fig.colormap = style.palettes.categorical

    if show:
        return fig.show()
    else:
        return fig

delta_dsm

1
2
3
4
5
6
7
delta_dsm(
    g1: Graph,
    g2: Graph,
    *args,
    style: Style = Style(),
    **kwargs
) -> Figure

Get a delta-DSM plot between two Graph objects.

Source code in ragraph/plot/__init__.py
def delta_dsm(g1: Graph, g2: Graph, *args, style: Style = Style(), **kwargs) -> go.Figure:
    """Get a delta-DSM plot between two Graph objects."""
    raise NotImplementedError()

dmm

dmm(
    rows: List[Node],
    cols: List[Node],
    edges: List[Edge],
    style: Style = Style(),
    sort: bool = True,
    row_node_kinds: Optional[List[str]] = None,
    row_sort_args: Dict[str, Any] = dict(),
    col_node_kinds: Optional[List[str]] = None,
    col_sort_args: Dict[str, Any] = dict(),
    show: bool = False,
) -> Figure

Get a domain-mapping-matrix (DMM) plot of a Graph object.

Parameters:

Name Type Description Default
rows List[Node]

The nodes to be placed on the rows of the matrix.

required
cols List[Node]

The columns to be placed on the columns of the matrix.

required
edges List[Edge]

Edges to be displayed between leaf nodes.

required
style Style

Plot style option mapping.

Style()
sort bool

Boolean to indicate whether the rows and cols should be sorted following the hierarchical structure.

True
row_node_kinds Optional[List[str]]

The node kinds displayed on the rows.

None
col_node_kinds Optional[List[str]]

The node kinds displayed on the columns.

None
show bool

Boolean to display the figure.

False

Returns:

Type Description
Figure

Domain-mapping matrix figure.

Source code in ragraph/plot/__init__.py
def dmm(
    rows: List[Node],
    cols: List[Node],
    edges: List[Edge],
    style: Style = Style(),
    sort: bool = True,
    row_node_kinds: Optional[List[str]] = None,
    row_sort_args: Dict[str, Any] = dict(),
    col_node_kinds: Optional[List[str]] = None,
    col_sort_args: Dict[str, Any] = dict(),
    show: bool = False,
) -> go.Figure:
    """Get a domain-mapping-matrix (DMM) plot of a Graph object.

    Arguments:
        rows: The nodes to be placed on the rows of the matrix.
        cols: The columns to be placed on the columns of the matrix.
        edges: Edges to be displayed between leaf nodes.
        style: Plot style option mapping.
        sort: Boolean to indicate whether the rows and cols should be sorted following
            the hierarchical structure.
        row_node_kinds: The node kinds displayed on the rows.
        col_node_kinds: The node kinds displayed on the columns.
        show: Boolean to display the figure.

    Returns:
       Domain-mapping matrix figure.
    """
    from ragraph.plot import utils

    if sort:
        rows = utils.get_axis_sequence(rows, kinds=row_node_kinds, **row_sort_args)
        cols = utils.get_axis_sequence(cols, kinds=col_node_kinds, **col_sort_args)

    grid = utils.get_dmm_grid(rows=rows, cols=cols, edges=edges, style=style)

    fig = utils.get_subplots(grid, style=style)
    return utils.process_fig(fig=fig, show=show, style=style)

dsm

1
2
3
4
5
6
7
8
9
dsm(
    leafs: List[Node],
    edges: List[Edge],
    style: Style = Style(),
    sort: bool = True,
    sort_args: Dict[str, Any] = dict(),
    node_kind: Optional[str] = None,
    show: bool = False,
) -> Figure

Get a DSM plot of a Graph object.

Arguments leafs: The nodes to be placed on the rows and columns of the matrix.. edges: Edges to be displayed between leaf nodes. style: Plot style option mapping. sort: Boolean to indicate whether the rows and cols should be sorted following the hierarchical structure. node_kind: The node kind to be displayed. show: Boolean to display the figure.

Source code in ragraph/plot/__init__.py
def dsm(
    leafs: List[Node],
    edges: List[Edge],
    style: Style = Style(),
    sort: bool = True,
    sort_args: Dict[str, Any] = dict(),
    node_kind: Optional[str] = None,
    show: bool = False,
) -> go.Figure:
    """Get a DSM plot of a Graph object.

    Arguments
        leafs: The nodes to be placed on the rows and columns of the matrix..
        edges: Edges to be displayed between leaf nodes.
        style: Plot style option mapping.
        sort: Boolean to indicate whether the rows and cols should be sorted following
            the hierarchical structure.
        node_kind: The node kind to be displayed.
        show: Boolean to display the figure.
    """
    node_kinds = [node_kind] if node_kind else list({n.kind for n in leafs})
    assert (
        len(node_kinds) == 1
    ), "A DSM should only contain one node kind. See MDM for multi-domain matrices."

    return mdm(
        leafs,
        edges,
        style=style,
        sort=sort,
        sort_args=sort_args,
        node_kinds=node_kinds,
        show=show,
    )

mdm

1
2
3
4
5
6
7
8
9
mdm(
    leafs: List[Node],
    edges: List[Edge],
    style: Style = Style(),
    sort: bool = True,
    sort_args: Dict[str, Any] = dict(),
    node_kinds: Optional[List[str]] = None,
    show: bool = False,
) -> Figure

Get a Multi-Domain Matrix (MDM) plot of a Graph object.

Arguments leafs: The nodes to be placed on the rows and columns of the matrix.. edges: Edges to be displayed between leaf nodes. style: Plot style option mapping. sort: Boolean to indicate whether the rows and cols should be sorted following the hierarchical structure. node_kinds: The node kinds displayed within the matrix. show: Boolean to display the figure.

Source code in ragraph/plot/__init__.py
def mdm(
    leafs: List[Node],
    edges: List[Edge],
    style: Style = Style(),
    sort: bool = True,
    sort_args: Dict[str, Any] = dict(),
    node_kinds: Optional[List[str]] = None,
    show: bool = False,
) -> go.Figure:
    """Get a Multi-Domain Matrix (MDM) plot of a Graph object.

    Arguments
        leafs: The nodes to be placed on the rows and columns of the matrix..
        edges: Edges to be displayed between leaf nodes.
        style: Plot style option mapping.
        sort: Boolean to indicate whether the rows and cols should be sorted following
            the hierarchical structure.
        node_kinds: The node kinds displayed within the matrix.
        show: Boolean to display the figure.
    """
    from ragraph.plot import utils

    if sort:
        leafs = utils.get_axis_sequence(leafs, kinds=node_kinds, **sort_args)

    grid = utils.get_mdm_grid(leafs=leafs, edges=edges, style=style)

    fig = utils.get_subplots(grid, style=style)

    return utils.process_fig(fig=fig, show=show, style=style)

network

1
2
3
network(
    g: Graph, *args, style: Style = Style(), **kwargs
) -> Figure

Get a network plot of a Graph object.

Source code in ragraph/plot/__init__.py
def network(g: Graph, *args, style: Style = Style(), **kwargs) -> go.Figure:
    """Get a network plot of a Graph object."""
    raise NotImplementedError()

sigma_dsm

1
2
3
4
5
6
sigma_dsm(
    graphs: Iterable[Graph],
    *args,
    style: Style = Style(),
    **kwargs
) -> Figure

Get a sigma-DSM plot of any number of Graph objects.

Source code in ragraph/plot/__init__.py
def sigma_dsm(graphs: Iterable[Graph], *args, style: Style = Style(), **kwargs) -> go.Figure:
    """Get a sigma-DSM plot of any number of Graph objects."""
    raise NotImplementedError()