Skip to content

Plot Context

This module provides the PlotContext class, which manages the state and context for plotting operations in Soundscapy.

Data and state management for plotting layers.

This module provides the PlotContext class that manages data and state for ISOPlot visualizations, enabling a more flexible architecture for plot generation with support for layered visualizations and subplot management.

CLASS DESCRIPTION
PlotContext

Manages data and state for a plot or subplot.

PlotContext

PlotContext(data=None, x='ISOPleasant', y='ISOEventful', hue=None, ax=None, title=None)

Manages data and state for a plot or subplot.

This class centralizes the management of data, coordinates, and other state needed for rendering plot layers, allowing for consistent data access patterns and simplified layer implementation.

ATTRIBUTE DESCRIPTION
data

The data associated with this context

TYPE: DataFrame

x

The column name for x-axis data

TYPE: str

y

The column name for y-axis data

TYPE: str

hue

The column name for color encoding, if any

TYPE: str | None

ax

The matplotlib Axes object this context is associated with

TYPE: Axes | None

title

The title for this context's plot

TYPE: str | None

layers

The visualization layers to be rendered on this context

TYPE: list

Initialize a PlotContext.

PARAMETER DESCRIPTION
data

Data to be visualized

TYPE: DataFrame | None DEFAULT: None

x

Column name for x-axis data

TYPE: str DEFAULT: 'ISOPleasant'

y

Column name for y-axis data

TYPE: str DEFAULT: 'ISOEventful'

hue

Column name for color encoding

TYPE: str | None DEFAULT: None

ax

Matplotlib axis to render on

TYPE: Axes | None DEFAULT: None

title

Title for this plot context

TYPE: str | None DEFAULT: None

METHOD DESCRIPTION
create_child

Create a child context that inherits properties from this context.

Source code in soundscapy/plotting/plot_context.py
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
def __init__(
    self,
    data: pd.DataFrame | None = None,
    x: str = "ISOPleasant",
    y: str = "ISOEventful",
    hue: str | None = None,
    ax: Axes | None = None,
    title: str | None = None,
) -> None:
    """
    Initialize a PlotContext.

    Parameters
    ----------
    data : pd.DataFrame | None
        Data to be visualized
    x : str
        Column name for x-axis data
    y : str
        Column name for y-axis data
    hue : str | None
        Column name for color encoding
    ax : Axes | None
        Matplotlib axis to render on
    title : str | None
        Title for this plot context

    """
    self.data = data
    self.x = x
    self.y = y
    self.hue = hue
    self.ax = ax
    self.title = title
    self.layers: list[Layer] = []
    self.parent: PlotContext | None = None

create_child

create_child(data=None, title=None, ax=None)

Create a child context that inherits properties from this context.

PARAMETER DESCRIPTION
data

Data for the child context. If None, inherits from parent.

TYPE: DataFrame | None DEFAULT: None

title

Title for the child context

TYPE: str | None DEFAULT: None

ax

Matplotlib axis for the child context

TYPE: Axes | None DEFAULT: None

RETURNS DESCRIPTION
PlotContext

A new child context with inherited properties

Source code in soundscapy/plotting/plot_context.py
 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
def create_child(
    self,
    data: pd.DataFrame | None = None,
    title: str | None = None,
    ax: Axes | None = None,
) -> PlotContext:
    """
    Create a child context that inherits properties from this context.

    Parameters
    ----------
    data : pd.DataFrame | None
        Data for the child context. If None, inherits from parent.
    title : str | None
        Title for the child context
    ax : Axes | None
        Matplotlib axis for the child context

    Returns
    -------
    PlotContext
        A new child context with inherited properties

    """
    child = PlotContext(
        data=data if data is not None else self.data,
        x=self.x,
        y=self.y,
        hue=self.hue,
        ax=ax,
        title=title,
    )
    child.parent = self
    return child

show_submodules: true