Skip to content

visu_plotly

visualize_with_plotly(input, degrees='all', display=True, highlight=None, **kwargs)

Display simplicial complexes with the plotly library.

Parameters:

Name Type Description Default
input Simplex or SimplicialComplex

The structure to display.

required
degrees int, list of int, or str

The (list of) simplex degree(s) to display. Default is 'all'.

'all'
display bool

If True, the figure is automatically displayed. Default is True.

True
highlight dict

Subset of simplices to highlight. If given as dict: - keys : int. simplex degrees. - values : list of int. collection of simplex indices.

None

Other Parameters:

Name Type Description
show_grid bool

If True, reveals the Euclidean grid. Default is False.

background tuple of int

RGB color code for the background. Each value should be between 0 and 255. Default is (255, 255, 255).

title str

The title of the graph to display. Default is None.

show str

What complex(es) to display. Should be in ['primal', 'dual', 'all']. Default is 'primal'.

color str

The main color of the graph. Default is 'darkblue'.

color_accent str

The color of the highlighted subset. Default is 'orange'.

size int

Size of the glyph representing 0-simplices. Default is 10.

width int

Thickness of lines representing 1-simplices. Default is 2.

scaling float

Scaling factor to visualize property values. Useful when plotting cochains. Default is 1.

window_size tuple of int

The width and height in pixels of the display window. Default is None.

Returns:

Type Description
Figure

The plotly figure object.

See Also

_generate_plot_data_manifold : Generates plot data for simplicial manifolds. _generate_plot_data_complex : Generates plot data for simplicial complexes. _generate_plot_data_simplex : Generates plot data for simplices.

Source code in src/dxtr/visu/visu_plotly.py
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 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
@typecheck([Simplex, SimplicialComplex])
def visualize_with_plotly(input: Simplex|SimplicialComplex,
                          degrees: int|list[int]|str='all',
                          display:bool=True,
                          highlight: Optional[dict]=None, 
                          **kwargs) -> go.Figure:
    """Display simplicial complexes with the plotly library.

    Parameters
    ----------
    input : Simplex or SimplicialComplex
        The structure to display.
    degrees : int, list of int, or str, optional
        The (list of) simplex degree(s) to display. Default is 'all'.
    display : bool, optional
        If True, the figure is automatically displayed. Default is True.
    highlight : dict, optional
        Subset of simplices to highlight. If given as dict:
            - keys : int. simplex degrees.
            - values : list of int. collection of simplex indices.

    Other Parameters
    ----------------
    show_grid : bool, optional
        If True, reveals the Euclidean grid. Default is False.
    background : tuple of int, optional
        RGB color code for the background. Each value should be between 0 and 255. Default is (255, 255, 255).
    title : str, optional
        The title of the graph to display. Default is None.
    show : str, optional
        What complex(es) to display. Should be in ['primal', 'dual', 'all']. Default is 'primal'.
    color : str, optional
        The main color of the graph. Default is 'darkblue'.
    color_accent : str, optional
        The color of the highlighted subset. Default is 'orange'.
    size : int, optional
        Size of the glyph representing 0-simplices. Default is 10.
    width : int, optional
        Thickness of lines representing 1-simplices. Default is 2.
    scaling : float, optional
        Scaling factor to visualize property values. Useful when plotting cochains. Default is 1.
    window_size : tuple of int, optional
        The width and height in pixels of the display window. Default is None.

    Returns
    -------
    go.Figure
        The plotly figure object.

    See Also
    --------
    _generate_plot_data_manifold : Generates plot data for simplicial manifolds.
    _generate_plot_data_complex : Generates plot data for simplicial complexes.
    _generate_plot_data_simplex : Generates plot data for simplices.
    """

    show_grid = kwargs.get('show_grid', False)
    background = kwargs.get('background', (255, 255, 255))
    title = kwargs.get('title', None)

    generate_plot_data = {Simplex: _generate_plot_data_simplex,
                          SimplicialComplex: _generate_plot_data_complex,
                          SimplicialManifold: _generate_plot_data_manifold}

    data = generate_plot_data[type(input)](input, degrees=degrees, 
                                           subset=highlight, **kwargs)

    layout = go.Layout(scene_xaxis_visible=show_grid,
                        scene_yaxis_visible=show_grid,
                        scene_zaxis_visible=show_grid,
                        paper_bgcolor='rgb'+str(background),
                        scene=dict(aspectmode="data"),
                        margin=dict(l=40, r=40, t=40, b=40),
                        width=kwargs.get('window_size', [None, None])[0], 
                        height=kwargs.get('window_size', [None, None])[1],
                        title=title)

    fig = go.Figure(data, layout)
    if display: fig.show()

    return fig