nikolasibalic / ARC-Alkali-Rydberg-Calculator

Object-oriented Python library for computation of properties of highly-excited Rydbeg states of alkali and divalent atoms.
https://atomcalc.org
BSD 3-Clause "New" or "Revised" License
86 stars 72 forks source link

Two graphs plotted in plot2D function #156

Closed Wasabi33 closed 2 months ago

Wasabi33 commented 10 months ago

Basically I noticed that two graphs are created in the plot2D function under the class Wavefunction. This I guess because you return the fig while u actually plotted it before. image image

nikolasibalic commented 2 months ago

Thank you for your comment @Wasabi33 ! This is specific to IPython.

IPython by default shows figure without explicit plt.show(). We can turn that off using plt.ioff(). Then executing say

import matplotlib.pyplot as plt
plt.ioff()

atom = Rubidium()
n = 10
l = 1
j = 1.5
mj = 1.5
wf = Wavefunction(atom, [[n, l, j, mj]], [1])
wf.plot2D(plane="x-z", units="atomic")

shows only one figure. That one figure is again specifics of IPython - it will show output of the last command. If we ended with say

...
wf.plot2D(plane="x-z", units="atomic")
someCalculation = 2 +3

or assigned last figure output to variable

fig1 = wf.plot2D(plane="x-z", units="atomic")

we would see no figures in output. Still we could see on demand later that figure either by running as last command in cell

fig1

or explicitly calling plt.show().

In either case, using some combination of above options, you can control output (probably the best by assigning fig1 = wf.plot2D(...)). But equally returning figure handle can be useful in some scenarios where you later use/add on on that figure, so I would prefer not change default behavior of returning figure.