r/learnpython • u/Joltik2007 • 11m ago
Trying to count a specific way.
Hello.
I am currently trying to create an energy level diagram and I need a way to count how many electrons are in each energy level.
For thse who don't know electrons pair up on each energy level.
So a diagram dipicting 3 electrons would look like this:
Whilst a diagram depicting 4 electrons would lok like this:
I currently have a set up where the orizontal lines are hlines that call back to dictionary and I'm currently trying to get the arrows to plot via the ax.annotate function to varying succsess. I can get them on the lines but they still print on every energy level rather than the lowest going upwards.
•
u/bytemender_dev 1m ago
I'd work out the counts first, then draw arrows from those — I kept getting arrows on every level until I split it that way. If you put your levels in a list from lowest to highest, you can hand out two electrons at a time:
remaining = n_electrons
for y in levels_bottom_to_top:
count = min(2, remaining)
remaining -= count
if count >= 1:
ax.annotate("↑", xy=(0, y))
if count == 2:
ax.annotate("↓", xy=(0.2, y))
With 3 electrons that gives you counts of 2, 1, 0, so the top level just never gets drawn on.