python/pycubool/gviz.py
def matrices_to_gviz(matrices: dict, **kwargs) -> str:
    """
    Export the labeled square matrices dictionary to the graph viz graph description script.
    All matrices must have the save shape.

    >>> name = "Test"                           # Displayed graph name
    >>> shape = (4, 4)                          # Adjacency matrices shape
    >>> colors = {"a": "red", "b": "green"}     # Colors per label
    >>>
    >>> a = Matrix.empty(shape=shape)        # Edges labeled as 'a'
    >>> a[0, 1] = True
    >>> a[1, 2] = True
    >>> a[2, 0] = True
    >>>
    >>> b = Matrix.empty(shape=shape)        # Edges labeled as 'b'
    >>> b[2, 3] = True
    >>> b[3, 2] = True
    >>>
    >>> print(matrices_to_gviz(matrices={"a": a, "b": b}, graph_name=name, edge_colors=colors))
    '
        digraph G {
            graph [label=Test];
            node [color=black];
            0 -> 1 [label=a,color=red];
            1 -> 2 [label=a,color=red];
            2 -> 0 [label=a,color=red];
            2 -> 3 [label=b,color=green];
            3 -> 2 [label=b,color=green];
        }
    '

    :param matrices: The dictionary with matrix label mapping to the pycubool Matrix instance
    :param kwargs: Optional arguments to tweak gviz graph appearance
        :param graph_name: Name of the graph
        :param base_vertex: Index of the base vertex (by default is 0)
        :param vertex_color: Color of the vertices (use \" - \" to pass html style hex colors)
        :param edges_colors: Dictionary with mapping matrix label to its edges colors (use \" - \" to pass html style hex colors)

    :return: Text script gviz graph representation
    """

    assert len(matrices) > 0

    base = next(iter(matrices.values()))
    shape = base.shape

    for m in matrices.values():
        assert m.shape == shape

    matrices_data = dict()

    for key, value in matrices.items():
        assert isinstance(value, Matrix)
        matrices_data[key] = value.to_lists()

    return matrices_data_to_gviz(shape=shape, matrices=matrices_data, **kwargs)

    Export the labeled square matrices dictionary to the graph viz graph description script.
    All matrices must have the save shape.

    >>> name = "Test"                           # Displayed graph name
    >>> shape = (4, 4)                          # Adjacency matrices shape
    >>> colors = {"a": "red", "b": "green"}     # Colors per label
    >>>
    >>> a = Matrix.empty(shape=shape)        # Edges labeled as 'a'
    >>> a[0, 1] = True
    >>> a[1, 2] = True
    >>> a[2, 0] = True
    >>>
    >>> b = Matrix.empty(shape=shape)        # Edges labeled as 'b'
    >>> b[2, 3] = True
    >>> b[3, 2] = True
    >>>
    >>> print(matrices_to_gviz(matrices={"a": a, "b": b}, graph_name=name, edge_colors=colors))
    '
        digraph G {
            graph [label=Test];
            node [color=black];
            0 -> 1 [label=a,color=red];
            1 -> 2 [label=a,color=red];
            2 -> 0 [label=a,color=red];
            2 -> 3 [label=b,color=green];
            3 -> 2 [label=b,color=green];
        }
    '

    :param matrices: The dictionary with matrix label mapping to the pycubool Matrix instance
    :param kwargs: Optional arguments to tweak gviz graph appearance
        :param graph_name: Name of the graph
        :param base_vertex: Index of the base vertex (by default is 0)
        :param vertex_color: Color of the vertices (use \" - \" to pass html style hex colors)
        :param edges_colors: Dictionary with mapping matrix label to its edges colors (use \" - \" to pass html style hex colors)

    :return: Text script gviz graph representation
    
Export the labeled square matrices dictionary to the graph viz graph description script.
All matrices must have the save shape.


Export the labeled square matrices dictionary to the graph viz graph description script . All matrices must have the save shape .
def matrices_to_gviz(matrices: dict, **kwargs) -> str:
    assert len(matrices) > 0
    base = next(iter(matrices.values()))
    shape = base.shape
    for m in matrices.values():
        assert m.shape == shape
    matrices_data = dict()
    for key, value in matrices.items():
        assert isinstance(value, Matrix)
        matrices_data[key] = value.to_lists()
    return matrices_data_to_gviz(shape=shape, matrices=matrices_data, **kwargs)
def matrices_to_gviz ( matrices : dict , ** kwargs ) -> str : assert len ( matrices ) > 0 base = next ( iter ( matrices . values ( ) ) ) shape = base . shape for m in matrices . values ( ) : assert m . shape == shape matrices_data = dict ( ) for key , value in matrices . items ( ) : assert isinstance ( value , Matrix ) matrices_data [ key ] = value . to_lists ( ) return matrices_data_to_gviz ( shape = shape , matrices = matrices_data , ** kwargs )
Export the labeled square matrices dictionary to the graph viz graph description script.
Export the labeled square matrices dictionary to the graph viz graph description script .
"""
    Export the labeled square matrices dictionary to the graph viz graph description script.
    All matrices must have the save shape.

    >>> name = "Test"                           # Displayed graph name
    >>> shape = (4, 4)                          # Adjacency matrices shape
    >>> colors = {"a": "red", "b": "green"}     # Colors per label
    >>>
    >>> a = Matrix.empty(shape=shape)        # Edges labeled as 'a'
    >>> a[0, 1] = True
    >>> a[1, 2] = True
    >>> a[2, 0] = True
    >>>
    >>> b = Matrix.empty(shape=shape)        # Edges labeled as 'b'
    >>> b[2, 3] = True
    >>> b[3, 2] = True
    >>>
    >>> print(matrices_to_gviz(matrices={"a": a, "b": b}, graph_name=name, edge_colors=colors))
    '
        digraph G {
            graph [label=Test];
            node [color=black];
            0 -> 1 [label=a,color=red];
            1 -> 2 [label=a,color=red];
            2 -> 0 [label=a,color=red];
            2 -> 3 [label=b,color=green];
            3 -> 2 [label=b,color=green];
        }
    '

    :param matrices: The dictionary with matrix label mapping to the pycubool Matrix instance
    :param kwargs: Optional arguments to tweak gviz graph appearance
        :param graph_name: Name of the graph
        :param base_vertex: Index of the base vertex (by default is 0)
        :param vertex_color: Color of the vertices (use \" - \" to pass html style hex colors)
        :param edges_colors: Dictionary with mapping matrix label to its edges colors (use \" - \" to pass html style hex colors)

    :return: Text script gviz graph representation
    """
Text script gviz graph representation
Text script gviz graph representation
matrices
dict
The dictionary with matrix label mapping to the pycubool Matrix instance
The dictionary with matrix label mapping to the pycubool Matrix instance
kwargs
Optional arguments to tweak gviz graph appearance
:param graph_name: Name of the graph
:param base_vertex: Index of the base vertex (by default is 0)
:param vertex_color: Color of the vertices (use \" - \" to pass html style hex colors)
:param edges_colors: Dictionary with mapping matrix label to its edges colors (use \" - \" to pass html style hex colors)
Optional arguments to tweak gviz graph appearance : param graph_name : Name of the graph : param base_vertex : Index of the base vertex ( by default is 0 ) : param vertex_color : Color of the vertices ( use \ " - \ " to pass html style hex colors ) : param edges_colors : Dictionary with mapping matrix label to its edges colors ( use \ " - \ " to pass html style hex colors )