Skip to content

chainconsumer.ChainConfig

Bases: BetterBase

The configuration for a chain. This is used to set the default values for plotting chains, and is also used to store the configuration of a chain.

Note that some attributes are defaulted to None instead of their type hint. Like color. This indicates that this parameter should be inferred if not explicitly set, and that this inference requires knowledge of the other chains. For example, if you have two chains, you probably want them to be different colors.

Source code in src/chainconsumer/chain.py
class ChainConfig(BetterBase):
    """The configuration for a chain. This is used to set the default values for
    plotting chains, and is also used to store the configuration of a chain.

    Note that some attributes are defaulted to None instead of their type hint.
    Like color. This indicates that this parameter should be inferred if not explicitly
    set, and that this inference requires knowledge of the other chains. For example,
    if you have two chains, you probably want them to be different colors.
    """

    statistics: SummaryStatistic = Field(default=SummaryStatistic.MAX, description="The summary statistic to use")
    summary_area: float = Field(default=0.6827, ge=0, le=1.0, description="The area to use for summary statistics")
    sigmas: list[float] = Field(default=[0, 1, 2], description="The sigmas to use for summary statistics")
    color: ColorInput | None = Field(default=None, description="The color of the chain")  # type: ignore
    linestyle: str = Field(default="-", description="The line style of the chain")
    linewidth: float = Field(default=1.0, description="The line width of the chain")
    show_contour_labels: bool = Field(default=False, description="Whether to show contour labels")
    shade: bool = Field(default=True, description="Whether to shade the chain")
    shade_alpha: float = Field(default=0.5, description="The alpha of the shading")
    shade_gradient: float = Field(default=1.0, description="The contrast between contour levels")
    bar_shade: bool = Field(default=True, description="Whether to shade marginalised distributions")
    bins: int | None = Field(default=None, description="The number of bins to use for histograms.")
    kde: int | float | bool = Field(default=False, description="The bandwidth for KDEs")
    smooth: int = Field(default=3, description="The smoothing for histograms. Set to 0 for no smoothing")
    color_param: str | None = Field(default=None, description="The parameter (column) to use for coloring")
    cmap: str = Field(default="viridis", description="The colormap to use for shading cloud points")
    num_cloud: int | float = Field(default=10000, description="The number of points in the cloud")
    plot_cloud: bool = Field(default=False, description="Whether to plot the cloud")
    plot_contour: bool = Field(default=True, description="Whether to plot contours")
    plot_point: bool = Field(default=False, description="Whether to plot points")
    marker_style: str = Field(default=".", description="The marker style to use")
    marker_size: int | float = Field(default=10.0, ge=1, description="The marker size to use")
    marker_alpha: int | float = Field(default=1.0, description="The marker alpha to use")
    zorder: int = Field(default=10, description="The zorder to use")
    shift_params: bool = Field(
        default=False,
        description="Whether to shift the parameters by subtracting each parameters mean",
    )

    @field_validator("color")
    @classmethod
    def _convert_color(cls, v: ColorInput | None) -> str | None:
        if v is None:
            return None
        return colors.format(v)

    def _apply_if_not_user_set(self, **kwargs: Any) -> None:
        for key, value in kwargs.items():
            if key not in self._user_specified:
                setattr(self, key, value)

    def _apply(self, **kwargs: Any) -> None:
        for key, value in kwargs.items():
            setattr(self, key, value)

statistics class-attribute instance-attribute

statistics: SummaryStatistic = Field(default=MAX, description='The summary statistic to use')

summary_area class-attribute instance-attribute

summary_area: float = Field(default=0.6827, ge=0, le=1.0, description='The area to use for summary statistics')

sigmas class-attribute instance-attribute

sigmas: list[float] = Field(default=[0, 1, 2], description='The sigmas to use for summary statistics')

color class-attribute instance-attribute

color: ColorInput | None = Field(default=None, description='The color of the chain')

linestyle class-attribute instance-attribute

linestyle: str = Field(default='-', description='The line style of the chain')

linewidth class-attribute instance-attribute

linewidth: float = Field(default=1.0, description='The line width of the chain')

show_contour_labels class-attribute instance-attribute

show_contour_labels: bool = Field(default=False, description='Whether to show contour labels')

shade class-attribute instance-attribute

shade: bool = Field(default=True, description='Whether to shade the chain')

shade_alpha class-attribute instance-attribute

shade_alpha: float = Field(default=0.5, description='The alpha of the shading')

shade_gradient class-attribute instance-attribute

shade_gradient: float = Field(default=1.0, description='The contrast between contour levels')

bar_shade class-attribute instance-attribute

bar_shade: bool = Field(default=True, description='Whether to shade marginalised distributions')

bins class-attribute instance-attribute

bins: int | None = Field(default=None, description='The number of bins to use for histograms.')

kde class-attribute instance-attribute

kde: int | float | bool = Field(default=False, description='The bandwidth for KDEs')

smooth class-attribute instance-attribute

smooth: int = Field(default=3, description='The smoothing for histograms. Set to 0 for no smoothing')

color_param class-attribute instance-attribute

color_param: str | None = Field(default=None, description='The parameter (column) to use for coloring')

cmap class-attribute instance-attribute

cmap: str = Field(default='viridis', description='The colormap to use for shading cloud points')

num_cloud class-attribute instance-attribute

num_cloud: int | float = Field(default=10000, description='The number of points in the cloud')

plot_cloud class-attribute instance-attribute

plot_cloud: bool = Field(default=False, description='Whether to plot the cloud')

plot_contour class-attribute instance-attribute

plot_contour: bool = Field(default=True, description='Whether to plot contours')

plot_point class-attribute instance-attribute

plot_point: bool = Field(default=False, description='Whether to plot points')

marker_style class-attribute instance-attribute

marker_style: str = Field(default='.', description='The marker style to use')

marker_size class-attribute instance-attribute

marker_size: int | float = Field(default=10.0, ge=1, description='The marker size to use')

marker_alpha class-attribute instance-attribute

marker_alpha: int | float = Field(default=1.0, description='The marker alpha to use')

zorder class-attribute instance-attribute

zorder: int = Field(default=10, description='The zorder to use')

shift_params class-attribute instance-attribute

shift_params: bool = Field(default=False, description='Whether to shift the parameters by subtracting each parameters mean')