Skip to content

Latex

Module including routines for creating latex visuals.

This module includes the following functions:

  • create_subfigures(images, captions, labels) - Creates a multi-image figure in latex.

create_subfigures(images, captions, labels)

Creates a multi-image figure in latex.

Parameters:

Name Type Description Default
images List[np.ndarray]

List of images to include in the figure.

required
captions List[str]

Corresponding captions for each subfigure.

required
labels List[str]

Corresponding labels for each subfigure.

required

Returns:

Type Description
str

The latex string for the figure.

Source code in cvt/visualization/latex.py
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
def create_subfigures(images: List[np.ndarray], captions: List[str], labels: List[str]) -> str:
    """Creates a multi-image figure in latex.

    Parameters:
        images: List of images to include in the figure.
        captions: Corresponding captions for each subfigure.
        labels: Corresponding labels for each subfigure.

    Returns:
        The latex string for the figure.
    """
    num_sub_figs = len(images)
    width_scale = 1/num_sub_figs

    figure = "\\begin{figure}\n"

    for n in range(num_sub_figs):
        figure +=   "\t\\centering\n" + \
                    "\t\\begin{{subfigure}}{{{w:.1f}\\textwidth}}\n".format(w=width_scale) + \
                        "\t\t\\centering\n" + \
                        "\t\t\\includegraphics[width=\\textwidth]{{{img}}}\n".format(img=images[n]) + \
                        "\t\t\\caption{{{caption}}}\n".format(caption=captions[n]) + \
                        "\t\t\\label{{fig:{label}}}\n".format(label=labels[n]) + \
                        "\t\\end{subfigure}\n\t\\hfill\n"
    figure +=   "\t\\caption{{{caption}}}\n".format(caption=captions[-1]) + \
                "\t\\label{{fig:{label}}}\n".format(label=labels[-1]) + \
                "\\end{figure}"

    return figure