I am a chemistry major so I am pretty new to python but I am writing some code that will ideally generate a plot of the energy levels of the hydrogen atom within a set of values. Technically I have succeeded (see following plot). As you can see tho the scaling on the lines near the top is very close together, which makes sense because the values are only very slightly different (on the scale of 10^-20) and the first number is on the scale of 10^-18. I was wondering if anyone has any advice for making it so these lines are easier to differentiate from one another? I have seen some people talking about zooming into a specific region and magnifying it in a separate box but I have been struggling to implement that into my own code.
import numpy
import math
import os
import matplotlib.pyplot as plt
import pandas as pd
n_max = 10 #This is the highest energy level you want to look at (ie: for energy levels 1-10 "n" would be 10)
m_e = 9.1093837015* 10 ** -31 # kg
e = 1.602176634* 10 ** -19 # C
vp = 1.113* 10 ** -10 # C^2 / Jm
h = 6.62607015 * 10 ** -34 # J*s
h_bar = h/(2 * math.pi)
n = numpy.linspace(1, n_max, n_max)
p1 = m_e * e **4
p2 = 2 * vp ** 2
p3 = h_bar ** 2
p4 = n ** 2
p5 = p2*p3*p4
e_lv = - p1/p5
for inte in e_lv:
x = range(0,n_max)
y = [inte]*n_max
plt.plot(x, y)
plt.xticks([])
This is what my code looks like so far.
A trick could be using a mathematical transformation, altough this is very domain-specific, so you should check which mathematical transformation are usually used to represent this type of plot in chemistry literature.
A suggested transformation could be:
Where E
is the energy level you computed in J, while E'
represents the absolute value of the exponent of the energy level, thus it is on a range of 18-20.
Since this mathematical transformation focus on energy level's exponent, its value is no longer measured in J.
If you apply this concept to your code:
import numpy
import math
import matplotlib.pyplot as plt
n_max = 10 #This is the highest energy level you want to look at (ie: for energy levels 1-10 "n" would be 10)
m_e = 9.1093837015* 10 ** -31 # kg
e = 1.602176634* 10 ** -19 # C
vp = 1.113* 10 ** -10 # C^2 / Jm
h = 6.62607015 * 10 ** -34 # J*s
h_bar = h/(2 * math.pi)
n = numpy.linspace(1, n_max, n_max)
p1 = m_e * e **4
p2 = 2 * vp ** 2
p3 = h_bar ** 2
p4 = n ** 2
p5 = p2*p3*p4
e_lv = - p1/p5
fig, ax = plt.subplots(1, 2)
for inte in e_lv:
x = range(0,n_max)
y = [inte]*n_max
ax[0].plot(x, y)
ax[0].set_xticks([])
ax[0].set_ylabel('Energy level')
ax[1].plot(x, -numpy.log10(numpy.abs(y)))
ax[1].set_xticks([])
ax[1].set_ylabel('Absolute value of exponent of energy level')
plt.tight_layout()
plt.show()