Skip to content

Create a plot for identified parameter value #112

@BaptisteDE

Description

@BaptisteDE

Create a plot to represent graphically the paramters, with upper and lower bounds, and the optimal values. It should look like a forest plot. Carefull parameters may have differents units.

Here is a GPT example code:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

params = [
    {"name": "Heat capacity", "opt": 4200, "lb": 4000, "ub": 4400, "unit": "J/kgK"},
    {"name": "Flow rate", "opt": 0.25, "lb": 0.1, "ub": 0.5, "unit": "kg/s"},
    {"name": "Conductivity", "opt": 0.8, "lb": 0.6, "ub": 1.2, "unit": "W/mK"},
]

fig = make_subplots(
    rows=len(params),
    cols=1,
    shared_yaxes=False,
    subplot_titles=[f"{p['name']} [{p['unit']}]" for p in params],
    vertical_spacing=0.25  # more space between plots
)

for i, p in enumerate(params, start=1):
    # Interval line
    fig.add_trace(
        go.Scatter(
            x=[p["lb"], p["ub"]],
            y=[0, 0],
            mode="lines",
            line=dict(color="gray", width=6),
            showlegend=False
        ),
        row=i, col=1
    )
    # Optimal point
    fig.add_trace(
        go.Scatter(
            x=[p["opt"]],
            y=[0],
            mode="markers",
            marker=dict(color="red", size=12),
            showlegend=False,
            hovertext=f"{p['name']}<br>Opt: {p['opt']}<br>Range: [{p['lb']}, {p['ub']}]"
        ),
        row=i, col=1
    )

    # Adjust x-axis
    fig.update_xaxes(
        range=[p["lb"]*0.9, p["ub"]*1.1],
        row=i, col=1,
        showgrid=True,
        title_text=""  # remove x-axis title to avoid overlap
    )
    fig.update_yaxes(visible=False, row=i, col=1)

# Layout tuning
fig.update_layout(
    height=150*len(params),
    width=700,
    title="Parameter Calibration Ranges",
    title_x=0.5,
    margin=dict(t=80, b=50)
)

fig.show()

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions