Plot Configuration

The trspecfit.config.plot.PlotConfig dataclass controls plotting appearance and behavior across trspecfit.

Use PlotConfig to keep plotting settings consistent across a project while still allowing local overrides for specific plots.

Usage Patterns

Basic usage

Create a standalone PlotConfig and pass it to plotting helpers.

from trspecfit import PlotConfig
from trspecfit.utils import plot as uplt

# Create config with custom settings
config = PlotConfig(x_label='Energy (eV)', x_dir='rev', dpi_plot=150)
uplt.plot_1d(data, x, config=config)

Using project settings

Load defaults from a Project (including values from project.yaml), then reuse the resulting config across plots.

from trspecfit import Project, PlotConfig
from trspecfit.utils import plot as uplt

project = Project(path='my_project', config_file='project.yaml')
config = PlotConfig.from_project(project)

# All plots use project settings
uplt.plot_1d(data, x, config=config)
uplt.plot_2d(data, x, y, config=config)

Per-plot overrides

Override selected settings in an individual plot call without changing the underlying config object.

uplt.plot_1d(data, x, config=config, x_dir='rev', colors=['red', 'blue'])

Create alternate configs

Create lightweight variations from a base config for publication, talks, or interactive analysis.

default_config = PlotConfig.from_project(project)
pub_config = default_config.copy(dpi_save=600, dpi_plot=150)
talk_config = default_config.copy(ticksize=14)

API Reference

Configuration of trspecfit plotting functions

class trspecfit.config.plot.PlotConfig(x_label: str = 'x axis', y_label: str = 'y axis', z_label: str = 'z axis', title: str = '', x_dir: str = 'def', x_type: str = 'lin', y_dir: str = 'def', y_type: str = 'lin', x_lim: tuple[float, float] | None = None, y_lim: tuple[float, float] | None = None, dpi_plot: int = 100, dpi_save: int = 300, res_mult: float = 5, z_colormap: str = 'viridis', z_colorbar: str = 'ver', z_type: str = 'lin', data_slice: list[list[int]] | None = None, z_lim: tuple[float, float] | None = None, colors: list[str] | None = None, linestyles: list[str] | None = None, linewidths: list[float] | None = None, markers: list[str] | None = None, markersizes: list[float] | None = None, alphas: list[float] | None = None, legend: list[str] | None = None, waterfall: float = 0, vlines: list[float] | None = None, hlines: list[float] | None = None, ticksize: float | None = None, y_norm: int = 0, y_scale: list[float] | None = None)[source]

Bases: object

Configuration for plot appearance and behavior.

This class bundles all plot-related settings that can be passed to plotting functions. It can be created standalone or from a Project instance.

x_label

X-axis label (energy for 2D, energy or time for 1D)

Type:

str

y_label

Y-axis label (time for 2D, intensity for 1D)

Type:

str

z_label

Z-axis/colorbar label (intensity for 2D plots)

Type:

str

title

Plot title

Type:

str

x_dir

X-axis direction: ‘def’ (default) or ‘rev’ (reversed)

Type:

str

x_type

X-axis scale: ‘lin’ (linear) or ‘log’ (logarithmic)

Type:

str

y_dir

Y-axis direction: ‘def’ (default) or ‘rev’ (reversed)

Type:

str

y_type

Y-axis scale: ‘lin’ (linear) or ‘log’ (logarithmic)

Type:

str

x_lim

X-axis limits (min, max)

Type:

tuple[float, float] | None

y_lim

Y-axis limits (min, max)

Type:

tuple[float, float] | None

z_type

Color scale type: ‘lin’ (linear) or ‘log’ (logarithmic)

Type:

str

z_lim

Color scale limits for 2D plots (min, max)

Type:

tuple[float, float] | None

dpi_plot

DPI for displaying plots

Type:

int

dpi_save

DPI for saving plots

Type:

int

z_colormap

Colormap name for 2D plots

Type:

str

data_slice

Data slicing indices for 2D plots: [[x_start, x_stop], [y_start, y_stop]]

Type:

list[list[int]] | None

colors

List of colors for line plots

Type:

list[str] | None

linestyles

List of line styles

Type:

list[str] | None

linewidths

List of line widths

Type:

list[float] | None

markers

List of marker styles

Type:

list[str] | None

markersizes

List of marker sizes

Type:

list[float] | None

alphas

List of opacity values (0–1) for each trace

Type:

list[float] | None

legend

List of legend labels

Type:

list[str] | None

waterfall

Y-offset between plots for waterfall display

Type:

float

vlines

X-coordinates for vertical lines

Type:

list[float] | None

hlines

Y-coordinates for horizontal lines

Type:

list[float] | None

ticksize

Font size for tick labels

Type:

float | None

Examples

Create a configuration with custom settings:

>>> config = PlotConfig(x_label='Energy (eV)', x_dir='rev', dpi_plot=150)
>>> plot_1d(data, x, config=config)

Create from Project settings:

>>> project = Project(path='...', config_file='project.yaml')
>>> config = PlotConfig.from_project(project)
>>> plot_1d(data, x, config=config)

Override Project settings:

>>> config = PlotConfig.from_project(project, x_label='Binding Energy (eV)')
>>> plot_2d(data, x, y, config=config)

Override config for a specific plot:

>>> config = PlotConfig.from_project(project)
>>> plot_1d(data, x, config=config, x_dir='rev', linewidth=2)

Create multiple configs from one project:

>>> project = Project(path='...')
>>> default_config = PlotConfig.from_project(project)
>>> pub_config = PlotConfig.from_project(project, dpi_save=600)
>>> talk_config = PlotConfig.from_project(project, dpi_plot=150)
copy(**overrides) PlotConfig[source]

Create a copy of this config with optional overrides.

Parameters:

**overrides (dict) – Attributes to override in the copy

Returns:

New configuration object

Return type:

PlotConfig

classmethod from_project(project, **overrides) PlotConfig[source]

Create PlotConfig from Project settings.

Parameters:
  • project (Project) – Project instance with plot settings

  • **overrides (dict) – Any parameters to override from project defaults

Returns:

Configuration object with settings from project

Return type:

PlotConfig

update(**kwargs) PlotConfig[source]

Update configuration attributes.

Parameters:

**kwargs (dict) – Attributes to update

Returns:

Self (for chaining)

Return type:

PlotConfig