Skip to content

API Reference

This section is rendered from the package's type hints and NumPy-style docstrings using mkdocstrings. Update the inline documentation in src/physics_plot/ and rebuild the docs to refresh the content.

physics_plot

utils

Handles

Bases: list

Container for legend handles derived from Matplotlib artists.

Source code in src/physics_plot/utils.py
 1
 2
 3
 4
 5
 6
 7
 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Handles(list):
    """Container for legend handles derived from Matplotlib artists."""

    def __init__(self, *args):
        """Initialize the handle list with optional starting values.

        Parameters
        ----------
        *args :
            Positional arguments forwarded to :class:`list`.
        """
        super().__init__(*args)

    def append(self, object):
        """Append an object to the handle list.
        If the object is a single-element list, append its only element
        instead.

        Parameters
        ----------
        object : Any
            Object to append to the handle list.

        Returns
        -------
        None
        """
        if isinstance(object, list) and len(object) == 1:
            super().append(object[0])
        else:
            super().append(object)

    def append_violinplot(self, violinplot, label):
        """Append a legend patch constructed from a violin plot.

        Parameters
        ----------
        violinplot : dict[str, list]
            Mapping returned by :meth:`matplotlib.axes.Axes.violinplot`.
        label : str
            Legend label describing the violin plot.

        Returns
        -------
        None
        """
        self.append(self._create_patch_from_violinplot(violinplot, label))

    def _create_patch_from_violinplot(self, violinplot, label):
        """Create a patch representing the first body of a violin plot.

        Parameters
        ----------
        violinplot : dict[str, list]
            Mapping returned by :meth:`matplotlib.axes.Axes.violinplot`.
        label : str
            Legend label describing the violin plot.

        Returns
        -------
        matplotlib.patches.Patch
            Patch configured with the violin plot's face color and label.
        """
        from matplotlib.patches import Patch

        body = violinplot["bodies"][0]
        color = body.get_facecolor()[0]
        return Patch(color=color, label=label)
__init__(*args)

Initialize the handle list with optional starting values.

Parameters:

Name Type Description Default
*args

Positional arguments forwarded to :class:list.

()
Source code in src/physics_plot/utils.py
 4
 5
 6
 7
 8
 9
10
11
12
def __init__(self, *args):
    """Initialize the handle list with optional starting values.

    Parameters
    ----------
    *args :
        Positional arguments forwarded to :class:`list`.
    """
    super().__init__(*args)
append(object)

Append an object to the handle list. If the object is a single-element list, append its only element instead.

Parameters:

Name Type Description Default
object Any

Object to append to the handle list.

required

Returns:

Type Description
None
Source code in src/physics_plot/utils.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def append(self, object):
    """Append an object to the handle list.
    If the object is a single-element list, append its only element
    instead.

    Parameters
    ----------
    object : Any
        Object to append to the handle list.

    Returns
    -------
    None
    """
    if isinstance(object, list) and len(object) == 1:
        super().append(object[0])
    else:
        super().append(object)
append_violinplot(violinplot, label)

Append a legend patch constructed from a violin plot.

Parameters:

Name Type Description Default
violinplot dict[str, list]

Mapping returned by :meth:matplotlib.axes.Axes.violinplot.

required
label str

Legend label describing the violin plot.

required

Returns:

Type Description
None
Source code in src/physics_plot/utils.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def append_violinplot(self, violinplot, label):
    """Append a legend patch constructed from a violin plot.

    Parameters
    ----------
    violinplot : dict[str, list]
        Mapping returned by :meth:`matplotlib.axes.Axes.violinplot`.
    label : str
        Legend label describing the violin plot.

    Returns
    -------
    None
    """
    self.append(self._create_patch_from_violinplot(violinplot, label))