Skip to content

Create plot to plot parameter distribution in Sample #113

@BaptisteDE

Description

@BaptisteDE

Represent all parameter density, like Overlapping densities (‘ridge plot’) of seaborn.

Bonus : add it at sampler level, and add a line to locate initial values.

Below is a GPT code example

import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from scipy.stats import gaussian_kde

# Example data: 200 simulations of 3 parameters with very different scales
np.random.seed(0)
n_sim = 200
data = np.column_stack([
    np.random.normal(500, 100, n_sim),    # Param A: 100–1000 range
    np.random.normal(0.2, 0.05, n_sim),   # Param B: 0–0.5 range
    np.random.normal(50, 10, n_sim)       # Param C: 20–80 range
])
param_names = ["Param A [J/kgK]", "Param B [kg/s]", "Param C [W/mK]"]

# Subplots: one per parameter
fig = make_subplots(
    rows=len(param_names), cols=1,
    shared_yaxes=False,
    subplot_titles=param_names,
    vertical_spacing=0.15
)

for i, pname in enumerate(param_names, start=1):
    values = data[:, i-1]

    # KDE
    kde = gaussian_kde(values)
    x_grid = np.linspace(values.min(), values.max(), 200)
    y = kde(x_grid)

    # Shift so baseline is "zero line" of this subplot
    fig.add_trace(
        go.Scatter(
            x=np.concatenate([x_grid, x_grid[::-1]]),
            y=np.concatenate([y, np.zeros_like(y)]),
            fill="toself",
            mode="lines",
            line=dict(color="steelblue"),
            name=pname,
            showlegend=False,
            hovertext=[f"{pname}<br>x={xx:.3g}, density={yy:.3f}" for xx, yy in zip(x_grid, y)]
        ),
        row=i, col=1
    )

    # Adjust x-axis for this param
    fig.update_xaxes(title=pname, row=i, col=1)
    fig.update_yaxes(visible=False, row=i, col=1)

fig.update_layout(
    title="Parameter Density Distributions",
    height=250*len(param_names),
    width=800,
    template="simple_white",
    margin=dict(t=80, b=40)
)

fig.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions