this should work
import copy
from munch import Munch
import plotly.graph_objects as go
cpts = ["model 1", "model 2", "model 3"]
results_list = [
Munch({'z': [-15.0, -15.5, -16.0, -16.5, -17.0, -17.5, -18.0, -18.5, -19.0, -19.5, -20.0], 'normal': [790.74, 1131.5, 1363.5, 1622.9, 1846.6, 2104.54, 2593.58, 2734.68, 2732.2, 3158.56, 3200.1], 'reduced': [394.0, 564.39, 683.01
, 816.22, 935.06, 1069.48, 1357.29, 1478.49, 1511.82, 1742.66, 1825.46], 'combined': [403.52, 649.68, 778.05, 935.51, 1060.37, 1215.63, 1568.57, 1685.59, 1640.24, 1940.06, 1964.09]})
Munch({'z': [-14.0, -14.5, -15.0, -15.5], 'normal': [614.32, 705.53, 1075.8, 1225.69], 'reduced': [307.15, 352.76, 537.9, 612.84], 'combined': [314.4, 385.14, 622.29, 711.17]})
Munch({'z': [-8.5, -9.0, -9.5, -10.0, -10.5, -11.0], 'normal': [133.78, 559.27, 585.97, 722.04, 1330.92, 1499.82], 'reduced': [66.88, 279.62, 281.19, 332.07, 666.29, 775.68], 'combined': [73.24, 364.27, 360.09, 381.49, 813.2, 90
7.54]})
]
fig = go.Figure()
buttons = []
visibilities = []
num = 0
for i, results in enumerate(results_list):
num += 1
_visible = True if num == 1 else False
visibilities.extend([False] * 3)
fig.add_trace(
go.Scatter(
name=f"{cpts[i]} - normal",
x=results["normal"],
y=results["z"],
showlegend=True,
visible=_visible,
mode="lines+markers",
line=dict(width=1,
color="red")
)
)
fig.add_trace(
go.Scatter(
name=f"{cpts[i]} - reduced",
x=results["reduced"],
y=results["z"],
showlegend=True,
visible=_visible,
mode="lines+markers",
line=dict(width=1,
color="blue")
)
)
fig.add_trace(
go.Scatter(
name=f"{cpts[i]} - combined",
x=results["combined"],
y=results["z"],
showlegend=True,
visible=_visible,
mode="lines+markers",
line=dict(width=1,
color="green")
)
)
fig.update_xaxes(title="Rc,Net,d [kN]")
fig.update_yaxes(title="PPN [m]")
fig.update_layout(legend=dict(
yanchor="top",
xanchor="right",
x=0.99,
y=0.99
))
for i, cpt in enumerate(cpts):
j = i * 3
k = j + 1
l = j + 2
_temp_visibilities = copy.deepcopy(visibilities)
_temp_visibilities[j] = True
_temp_visibilities[k] = True
_temp_visibilities[l] = True
buttons.append(
dict(
label=cpts[i],
method="update",
args=[{"visible": _temp_visibilities}, {"title": f"{cpts[i]} - Rc,Net,D"}]
)
)
updatemenus = list(
[dict(direction="down", x=1.0, y=1.1, buttons=buttons, showactive=False, xanchor="right", yanchor="top",
active=0)]
)
fig.update_layout(updatemenus=updatemenus, title_text=f"{cpts[0]} - Rc,Net,D")