Skip to content

visu

plantimager.webui.visu Link

plotly_image_carousel(images, height=900, width=900, title='Carousel', layout_kwargs=None)

An image carousel based on Plotly.

Parameters:

Name Type Description Default
images list

The list of image to represent, should be convertible into numpy array.

required
height float

The height of the figure to create, in pixels. Defaults to 900.

900
width float

The width of the figure to create, in pixels. Defaults to 900.

900
title str

The title to give to the figure. Defaults to "Carousel".

'Carousel'
layout_kwargs dict

A dictionary to customize the figure layout.

None

Returns:

Type Description
Figure

The plotly figure to display.

See Also

plotly.graph_objects.Figure

References

Plotly documentation for Layout: https://plotly.com/python/reference/layout/

Source code in plantimager/webui/visu.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def plotly_image_carousel(images, height=900, width=900, title="Carousel", layout_kwargs=None):
    """An image carousel based on Plotly.

    Parameters
    ----------
    images : list
        The list of image to represent, should be convertible into numpy array.
    height : float, optional
        The height of the figure to create, in pixels.
        Defaults to ``900``.
    width : float, optional
        The width of the figure to create, in pixels.
        Defaults to ``900``.
    title : str, optional
        The title to give to the figure.
        Defaults to ``"Carousel"``.
    layout_kwargs : dict, optional
        A dictionary to customize the figure layout.

    Returns
    -------
    plotly.graph_objects.Figure
        The plotly figure to display.

    See Also
    --------
    plotly.graph_objects.Figure

    References
    ----------
    Plotly documentation for `Layout`: https://plotly.com/python/reference/layout/

    """
    import plotly.express as px

    layout_style = {'height': height, 'width': width, 'title': title, 'showlegend': False,
                    'xaxis': {'visible': False}, 'yaxis': {'visible': False}}
    if isinstance(layout_kwargs, dict):
        layout_style.update(layout_kwargs)

    array = np.array([np.array(img) for img in images])
    fig = px.imshow(array, animation_frame=0, binary_string=True, labels=dict(animation_frame="Image"))
    fig.update_layout(**layout_style)
    fig.update_scenes(aspectmode='data')

    return fig