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:
objectConfiguration 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.
- data_slice
Data slicing indices for 2D plots: [[x_start, x_stop], [y_start, y_stop]]
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:
- classmethod from_project(project, **overrides) PlotConfig[source]
Create PlotConfig from Project settings.
- Parameters:
- Returns:
Configuration object with settings from project
- Return type:
- update(**kwargs) PlotConfig[source]
Update configuration attributes.
- Parameters:
**kwargs (dict) – Attributes to update
- Returns:
Self (for chaining)
- Return type: