Plotting internals¶
These modules support the plotting package but are better treated as implementation details than as primary user entry points.
Defaults¶
soundscapy.plotting.defaults
¶
Default parameters and constants for soundscape plotting functions.
This module provides common default values used for various plot types, including density plots, scatter plots, and styling parameters. It contains predefined color schemes, font settings, and layout configurations to ensure consistent visualization across the package.
Layers¶
soundscapy.plotting.layers
¶
Layer-based visualization components for plotting.
This module provides a system of layer classes that implement different visualization techniques for ISO plots. Each layer encapsulates a specific visualization method and knows how to render itself on a given context.
| CLASS | DESCRIPTION |
|---|---|
Layer |
Base class for all visualization layers. |
ScatterLayer |
Layer for rendering scatter plots. |
DensityLayer |
Layer for rendering kernel density plots. |
SimpleDensityLayer |
Layer for rendering simplified density plots with fewer contour levels. |
SPILayer |
Layer for rendering SPI plots. |
SPISimpleLayer |
Layer for rendering simplified SPI plots with fewer contour levels. |
SPIDensityLayer |
Layer for rendering simplified SPI plots with fewer contour levels. |
SPIScatterLayer |
Layer for rendering simplified SPI plots with fewer contour levels. |
Layer
¶
Layer(
custom_data: DataFrame | None = None,
param_model: type[SeabornParams] = SeabornParams,
**params: Any,
)
Base class for all visualization layers.
A Layer encapsulates a specific visualization technique and its associated parameters. Layers know how to render themselves onto a PlotContext's axes.
| ATTRIBUTE | DESCRIPTION |
|---|---|
custom_data |
Optional custom data for this specific layer, overriding context data
TYPE:
|
params |
Parameter model instance for this layer
TYPE:
|
Initialize a Layer.
| PARAMETER | DESCRIPTION |
|---|---|
custom_data
|
Optional custom data for this specific layer, overriding context data
TYPE:
|
param_model
|
The parameter model class to use, if None uses a generic ParamModel
TYPE:
|
**params
|
Parameters for the layer
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
render |
Render this layer on the given context. |
Source code in src/soundscapy/plotting/layers.py
render
¶
Render this layer on the given context.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
The context containing data and axes for rendering
TYPE:
|
Source code in src/soundscapy/plotting/layers.py
ScatterLayer
¶
Bases: Layer
Layer for rendering scatter plots.
Initialize a ScatterLayer.
| PARAMETER | DESCRIPTION |
|---|---|
custom_data
|
Optional custom data for this specific layer
TYPE:
|
**params
|
Parameters for the scatter plot
TYPE:
|
Source code in src/soundscapy/plotting/layers.py
DensityLayer
¶
DensityLayer(
custom_data: DataFrame | None = None,
*,
param_model: type[DensityParams] = DensityParams,
include_outline: bool = False,
**params: Any,
)
Bases: Layer
Layer for rendering kernel density plots.
Initialize a DensityLayer.
| PARAMETER | DESCRIPTION |
|---|---|
custom_data
|
Optional custom data for this specific layer
TYPE:
|
include_outline
|
Whether to include an outline around the density plot
TYPE:
|
**params
|
Parameters for the density plot
TYPE:
|
Source code in src/soundscapy/plotting/layers.py
SimpleDensityLayer
¶
SimpleDensityLayer(
custom_data: DataFrame | None = None,
*,
include_outline: bool = True,
param_model: type[
SimpleDensityParams
] = SimpleDensityParams,
**params: Any,
)
Bases: DensityLayer
Layer for rendering simplified density plots with fewer contour levels.
Initialize a SimpleDensityLayer.
| PARAMETER | DESCRIPTION |
|---|---|
custom_data
|
Optional custom data for this specific layer
TYPE:
|
include_outline
|
Whether to include an outline around the density plot
TYPE:
|
**params
|
Parameters for the density plot
TYPE:
|
Source code in src/soundscapy/plotting/layers.py
SPILayer
¶
SPILayer(
spi_target_data: DataFrame | ndarray | None = None,
*,
msn_params: DirectParams | CentredParams | None = None,
n: int = 10000,
param_model: type[SPISeabornParams] = SPISeabornParams,
**params: Any,
)
Bases: Layer
Layer for rendering SPI plots.
Initialize an SPILayer.
| PARAMETER | DESCRIPTION |
|---|---|
spi_target_data
|
Pre-sampled data for SPI target distribution. When None, msn_params must be provided.
TYPE:
|
msn_params
|
Parameters to generate SPI data if no spi_target_data is provided
TYPE:
|
n
|
Number of samples to generate if using msn_params
TYPE:
|
param_model
|
The parameter model class to use
TYPE:
|
**params
|
Parameters for the layer. For compatibility with other layers, if 'custom_data' is present and spi_target_data is None, custom_data will be used as the SPI target data.
TYPE:
|
Notes
Either spi_target_data or msn_params must be provided, but not both. The test data for SPI calculations will be retrieved from the plot context.
| METHOD | DESCRIPTION |
|---|---|
render |
Render this layer on the given context. |
show_score |
Show the SPI score on the plot. |
Source code in src/soundscapy/plotting/layers.py
render
¶
Render this layer on the given context.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
The context containing data and axes for rendering
TYPE:
|
Source code in src/soundscapy/plotting/layers.py
show_score
¶
show_score(
spi_sc: int | None,
show_score: Literal["on axis", "under title"],
context: PlotContext,
ax: Axes,
axis_text_kwargs: dict[str, Any],
) -> None
Show the SPI score on the plot.
| PARAMETER | DESCRIPTION |
|---|---|
spi_sc
|
The SPI score to show
TYPE:
|
show_score
|
Where to show the score
TYPE:
|
context
|
The context containing data and axes for rendering
TYPE:
|
ax
|
The axes to render the score on
TYPE:
|
axis_text_kwargs
|
Additional arguments for the axis text |
Source code in src/soundscapy/plotting/layers.py
SPISimpleLayer
¶
SPISimpleLayer(
spi_target_data: DataFrame | ndarray | None = None,
*,
msn_params: DirectParams | CentredParams | None = None,
include_outline: bool = True,
**params: Any,
)
Bases: SPILayer, SimpleDensityLayer
Layer for rendering simplified SPI plots with fewer contour levels.
Initialize an SPISimpleLayer.
| PARAMETER | DESCRIPTION |
|---|---|
spi_target_data
|
Optional SPI target data for this specific layer
TYPE:
|
msn_params
|
Parameters to generate SPI data if no custom data is provided
TYPE:
|
include_outline
|
Whether to include an outline around the density plot
TYPE:
|
**params
|
Parameters for the density plot
TYPE:
|
Source code in src/soundscapy/plotting/layers.py
SPIDensityLayer
¶
Bases: SPILayer, DensityLayer
Layer for rendering simplified SPI plots with fewer contour levels.
Initialize SPIDensityLayer.
This initialization is not supported and will raise NotImplementedError. Use SPISimpleLayer instead.
Source code in src/soundscapy/plotting/layers.py
SPIScatterLayer
¶
Bases: SPILayer, ScatterLayer
Layer for rendering simplified SPI plots with fewer contour levels.
Initialize SPIScatterLayer.
This initialization is not supported and will raise NotImplementedError. Use SPISimpleLayer instead.
Source code in src/soundscapy/plotting/layers.py
Parameter models¶
soundscapy.plotting.param_models
¶
Parameter models for plotting functions in soundscapy.
This module provides parameter validation and management classes for various plotting functions using Pydantic dataclasses. The module includes:
- Base ParamModel class with common functionality
- SeabornParams for seaborn plotting parameters
- Specialized parameter classes for different plot types
- Style and subplot configuration classes
The parameter models provide:
- Type validation and conversion
- Default value management
- Parameter updating with validation
- Dictionary-style access to parameters
- Deep copying functionality
| CLASS | DESCRIPTION |
|---|---|
ParamModel |
Base model for parameter validation using dataclasses. |
SeabornParams |
Base parameters for seaborn plotting functions. |
ScatterParams |
Parameters for scatter plot functions. |
DensityParams |
Parameters for density plot functions. |
SimpleDensityParams |
Parameters for simple density plot functions. |
SPISeabornParams |
Base parameters for SPI (Soundscape Perceptual Index) seaborn plotting functions. |
SPISimpleDensityParams |
Parameters for SPI simple density plot functions. |
JointPlotParams |
Parameters for joint plot functions. |
StyleParams |
Parameters for plot styling. |
SubplotsParams |
Parameters for subplots. |
ParamModel
¶
Base model for parameter validation using dataclasses.
This class provides the foundation for all parameter models with common configuration settings and utility methods.
| METHOD | DESCRIPTION |
|---|---|
__post_init__ |
Process extra fields after initialization. |
update |
Update the attributes of the instance based on the provided parameters. |
get_defaults |
Get the default values for all defined fields in the model. |
get |
Get a parameter value with a default fallback. |
__getitem__ |
Get a parameter value using dictionary-style access. |
as_dict |
Get all parameters as a dictionary. |
copy |
Create a deep copy of the parameter model instance. |
model_copy |
Create a copy of the parameter model instance. |
get_changed_params |
Get parameters that have been changed from their defaults. |
get_multiple |
Get multiple parameters as a dictionary. |
pop |
Remove a parameter and return its value. |
drop |
Remove a parameter without returning its value. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
defaults |
Property to access default field values. |
defined_field_names |
Get the names of all fields defined for the model. |
current_field_names |
Get the names of all current fields. |
defaults
property
¶
defined_field_names
property
¶
current_field_names
property
¶
__post_init__
¶
Process extra fields after initialization.
Source code in src/soundscapy/plotting/param_models.py
update
¶
update(
*,
extra: Literal["allow", "forbid", "ignore"] = "allow",
ignore_null: bool = True,
**kwargs: Any,
) -> None
Update the attributes of the instance based on the provided parameters.
| PARAMETER | DESCRIPTION |
|---|---|
extra
|
Determines how to handle extra fields in
TYPE:
|
ignore_null
|
If True, removes
TYPE:
|
**kwargs
|
Field names and values to be updated.
TYPE:
|
Source code in src/soundscapy/plotting/param_models.py
get_defaults
¶
Get the default values for all defined fields in the model.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary mapping field names to their default values.
Excludes the special |
Source code in src/soundscapy/plotting/param_models.py
get
¶
Get a parameter value with a default fallback.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Name of the parameter
TYPE:
|
default
|
Default value if parameter doesn't exist
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Parameter value or default |
Source code in src/soundscapy/plotting/param_models.py
__getitem__
¶
Get a parameter value using dictionary-style access.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Name of the parameter
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Parameter value |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the parameter doesn't exist |
Source code in src/soundscapy/plotting/param_models.py
as_dict
¶
copy
¶
Create a deep copy of the parameter model instance.
| RETURNS | DESCRIPTION |
|---|---|
ParamModel
|
A deep copy of the current instance with all nested objects copied. |
Source code in src/soundscapy/plotting/param_models.py
model_copy
¶
Create a copy of the parameter model instance.
Deprecated
This method is deprecated. Use :meth:copy instead.
Kept only for backwards compatibility with Pydantic.
| RETURNS | DESCRIPTION |
|---|---|
ParamModel
|
A deep copy of the current instance. |
Source code in src/soundscapy/plotting/param_models.py
get_changed_params
¶
Get parameters that have been changed from their defaults.
This method compares the current parameter values against the default values and returns a dictionary containing only the parameters that differ from their defaults.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of changed parameters and their current values. |
Source code in src/soundscapy/plotting/param_models.py
get_multiple
¶
pop
¶
Remove a parameter and return its value.
For fields defined in the model, the value is reset to its default.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Name of the parameter
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Value of the removed parameter |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the parameter doesn't exist |
Source code in src/soundscapy/plotting/param_models.py
drop
¶
Remove a parameter without returning its value.
| PARAMETER | DESCRIPTION |
|---|---|
keys
|
Name of the parameter or list of parameters |
ignore_missing
|
If True, ignore missing keys. If False, raise KeyError for missing keys.
TYPE:
|
Source code in src/soundscapy/plotting/param_models.py
SeabornParams
¶
Bases: ParamModel
Base parameters for seaborn plotting functions.
Provides common parameters used across seaborn plotting functions including data source, aesthetic mappings, and color settings.
| METHOD | DESCRIPTION |
|---|---|
crosscheck_palette_hue |
Check if the palette is valid for the given hue. |
as_seaborn_kwargs |
Convert parameters to kwargs compatible with seaborn functions. |
crosscheck_palette_hue
¶
Check if the palette is valid for the given hue.
This method ensures that palette is only used when hue is provided.
Source code in src/soundscapy/plotting/param_models.py
ScatterParams
¶
Bases: SeabornParams
Parameters for scatter plot functions.
Inherits from SeabornParams and adds scatter-specific parameters.
DensityParams
¶
Bases: SeabornParams
Parameters for density plot functions.
Inherits from SeabornParams and adds density-specific parameters for contour plots and kernel density estimation.
| METHOD | DESCRIPTION |
|---|---|
as_seaborn_kwargs |
Convert parameters to kwargs compatible with seaborn functions. |
to_outline |
Convert to outline parameters. |
as_seaborn_kwargs
¶
Convert parameters to kwargs compatible with seaborn functions.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of parameter values suitable for seaborn plotting functions. |
Source code in src/soundscapy/plotting/param_models.py
to_outline
¶
Convert to outline parameters.
| PARAMETER | DESCRIPTION |
|---|---|
alpha
|
Alpha value for the outline.
TYPE:
|
fill
|
Whether to fill the outline.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DensityParams
|
New instance with outline parameters. |
Source code in src/soundscapy/plotting/param_models.py
SimpleDensityParams
¶
Bases: DensityParams
Parameters for simple density plot functions.
Inherits from DensityParams with overridden defaults for simplified density plots with fewer contour levels.
SPISeabornParams
¶
Bases: SeabornParams
Base parameters for SPI (Soundscape Perceptual Index) seaborn plotting functions.
Specialized parameters for plotting SPI data with specific styling and annotation options.
| METHOD | DESCRIPTION |
|---|---|
as_seaborn_kwargs |
Convert parameters to kwargs compatible with seaborn functions. |
as_seaborn_kwargs
¶
Convert parameters to kwargs compatible with seaborn functions.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of parameter values suitable for seaborn plotting functions. |
Source code in src/soundscapy/plotting/param_models.py
SPISimpleDensityParams
¶
Bases: SPISeabornParams, SimpleDensityParams
Parameters for SPI simple density plot functions.
Combines SPI-specific parameters with simple density plot parameters through multiple inheritance.
JointPlotParams
¶
Bases: ParamModel
Parameters for joint plot functions.
Parameters for creating joint plots that show both the relationship between two variables and their individual distributions.
StyleParams
¶
Bases: ParamModel
Parameters for plot styling.
Controls the visual appearance of plots including axes limits, labels, lines, and text formatting.
SubplotsParams
¶
Bases: ParamModel
Parameters for subplots.
Controls the layout and configuration of subplot grids, including figure size, sharing of axes, and automatic allocation.
| METHOD | DESCRIPTION |
|---|---|
as_plt_subplots_args |
Pass matplotlib subplot arguments to a plt.subplots call. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_subplots_by |
"The number of subplots allocated for each subplot_by category.
TYPE:
|
n_subplots |
Get the number of subplots.
TYPE:
|
n_subplots_by
class-attribute
instance-attribute
¶
"The number of subplots allocated for each subplot_by category.
as_plt_subplots_args
¶
Pass matplotlib subplot arguments to a plt.subplots call.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of subplot parameters. |
Source code in src/soundscapy/plotting/param_models.py
Plot context¶
soundscapy.plotting.plot_context
¶
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: DataFrame | None = None,
x: str = "ISOPleasant",
y: str = "ISOEventful",
hue: str | None = None,
ax: Axes | None = None,
title: str | None = 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
|
x |
The column name for x-axis data
|
y |
The column name for y-axis data
|
hue |
The column name for color encoding, if any
|
ax |
The matplotlib Axes object this context is associated with
|
title |
The title for this context's plot
|
layers |
The visualization layers to be rendered on this context |
Initialize a PlotContext.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Data to be visualized
TYPE:
|
x
|
Column name for x-axis data
TYPE:
|
y
|
Column name for y-axis data
TYPE:
|
hue
|
Column name for color encoding
TYPE:
|
ax
|
Matplotlib axis to render on
TYPE:
|
title
|
Title for this plot context
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
create_child |
Create a child context that inherits properties from this context. |
Source code in src/soundscapy/plotting/plot_context.py
create_child
¶
create_child(
data: DataFrame | None = None,
title: str | None = None,
ax: Axes | None = None,
) -> PlotContext
Create a child context that inherits properties from this context.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Data for the child context. If None, inherits from parent.
TYPE:
|
title
|
Title for the child context
TYPE:
|
ax
|
Matplotlib axis for the child context
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PlotContext
|
A new child context with inherited properties |
Source code in src/soundscapy/plotting/plot_context.py
Deprecated backends¶
soundscapy.plotting.backends_deprecated
¶
Deprecation warnings for v0.7 APIs.
| CLASS | DESCRIPTION |
|---|---|
CircumplexPlot |
Alias for v0.7 API to raise deprecation warnings. |
CircumplexPlotParams |
Alias for v0.7 API to raise deprecation warnings. |
Backend |
Alias for v0.7 API to raise deprecation warnings. |
PlotType |
Alias for v0.7 API to raise deprecation warnings. |
StyleOptions |
Alias for v0.7 API to raise deprecation warnings. |
CircumplexPlot
¶
Alias for v0.7 API to raise deprecation warnings.
Source code in src/soundscapy/plotting/backends_deprecated.py
CircumplexPlotParams
¶
Alias for v0.7 API to raise deprecation warnings.
Source code in src/soundscapy/plotting/backends_deprecated.py
PlotType
¶
Alias for v0.7 API to raise deprecation warnings.
StyleOptions
¶
Alias for v0.7 API to raise deprecation warnings.