r/learnpython • u/Joltik2007 • 26m ago
Help with plotting annotations
I've been constructing a code to plot the atomic energy orbitals using matplotlib.pyplot. This is the actual plotting code.
levels = {f"{val.real:.3f}": float(round(val.real,3)) * -1 for val in sorted(eigenvalues)}
fig, ax = plt.subplots()
for i, (name, e) in enumerate(levels.items()):
ax.hlines(e, 0, 0.5, color="k", lw=2)
ax.text(0.5 + 0.35, e, name+' \u03B2', va="center")
for i in eigenvalues:
count = min(2, atoms)
atoms -= count
if count >= 1:
ax.annotate("", xy=(0.15, e+0.3),xytext=(0.15, e-0.2),arrowprops=dict(arrowstyle='simple', color = 'k'))
if count == 2:
ax.annotate("", xy=(0.35, e-0.3),xytext=(0.35, e+0.2),arrowprops=dict(arrowstyle='simple', color = 'k'))
ax.set_xlim(-0.5, len(levels))
ax.set_xticks([])
for side in ("top", "right", "bottom"):
ax.spines[side].set_visible(False)
ax.set_ylabel("Energy -->")
It's designed to construct this kind of graph when the variable atoms is =3
|
|---- -√2 β
|
|
|--↑-- 0 β
|
|-↑--↓- √2 β
But what the code only seems to produce is when atoms =3
|
|---- -√2 β
|
|
|----- 0 β
|
|-↑--- √2 β