fig = go.Figure()
colors = ["#6C5CE7","#0984E3","#00B894","#FDCB6E","#E17055","#D63031","#A29BFE","#FD79A8","#55EFC4","#B2BEC3"]
# Draw energy levels as horizontal lines
for i, (n, E) in enumerate(zip(n_vals, E_n)):
fig.add_shape(
type="line",
x0=0.1, x1=0.9,
y0=E, y1=E,
line=dict(color=colors[i], width=2.5)
)
fig.add_annotation(
x=0.93, y=E,
text=f"n={n} {E:.2f} eV",
showarrow=False,
font=dict(size=11, color=colors[i]),
xanchor="left"
)
# Draw a few transitions (Lyman series, n→1)
lyman_upper = [2, 3, 4]
for n_upper in lyman_upper:
E_upper = E1 / n_upper**2
E_lower = E1
delta_E = E_upper - E_lower
wavelength_nm = 1240 / abs(delta_E)
fig.add_annotation(
x=0.5, y=(E_upper + E_lower) / 2,
ax=0.5, ay=(E_upper + E_lower) / 2,
axref="x", ayref="y",
xref="x", yref="y",
showarrow=True,
arrowhead=2,
arrowsize=1.2,
arrowwidth=1.5,
arrowcolor="#636E72",
text=f"λ={wavelength_nm:.0f} nm",
font=dict(size=9, color="#636E72"),
xanchor="right"
)
fig.update_layout(
title="Hydrogen Atom Energy Levels",
xaxis=dict(visible=False, range=[0, 1.4]),
yaxis=dict(
title="Energy (eV)",
range=[-15, 1],
tickvals=list(E_n[:6]),
ticktext=[f"{E:.2f}" for E in E_n[:6]],
gridcolor="rgba(150,150,150,0.15)"
),
plot_bgcolor="white",
paper_bgcolor="white",
height=600,
margin=dict(l=60, r=180, t=60, b=40),
font=dict(family="serif")
)
fig.show()