import mmf_setup

mmf_setup.nbinit()
from gpe.imports import *

This cell adds /home/docs/checkouts/readthedocs.org/user_builds/gpe/checkouts/latest/src to your path, and contains some definitions for equations and some CSS for styling the notebook. If things look a bit strange, please try the following:

  • Choose "Trust Notebook" from the "File" menu.
  • Re-execute this cell.
  • Reload the notebook.

[I 03:38:08 numexpr.utils] NumExpr defaulting to 2 threads.
[I 03:38:09 root] Patching zope.interface.document.asReStructuredText to format code

Plotting#

Here we demonstrate some tools for plotting, animating results, and making movies.

MPLGrid#

Here as a simple example, we start with a harmonically trapped gas, phase imprint a dark soliton, and then watch the “evolution” as we cool into the soliton state.

from gpe.bec import State, u

s = State(Nxyz=(128,), Lxyz=(20.0,))
s[:] *= np.sign(s.xyz[0])
s.cooling_phase = 1j
e = EvolverABM(s, dt=0.1 * s.t_scale)


def plot(state):
    plt.plot(state.xyz[0] / u.micron, state.get_density())


states = [s]
with NoInterrupt(ignore=True) as interrupted:
    for n in range(6):
        e.evolve(200)
        states.append(e.get_y())
        plt.clf()
        plot(e.y)
        display(plt.gcf())
        clear_output(wait=True)
../_images/82ceb278a0df01ca53f5c06882153d3499aa8f27266feceac3ed3a0451f78b88.png

Our first demonstration is to stack these frames using MPLGrid. We can stack going down or going right.

direction='down'#

import gpe.plot_utils

reload(gpe.plot_utils)
from gpe.plot_utils import MPLGrid

plt.figure(figsize=(10, 5))
grid = MPLGrid(direction="down", share=True)
for s in states:
    ax = grid.next()
    ax.plot(s.xyz[0] / u.micron, s.get_density())
plt.tight_layout()
../_images/99f88b62b47a65c59680ee0bb896bf9b051eb8459eb14197bf78276da2fdf1e2.png

direction='right'#

The plots can also be stacked to the right:

plt.figure(figsize=(15, 2))
grid = MPLGrid(direction="right", share=True)
for s in states:
    ax = grid.next()
    ax.plot(s.xyz[0] / u.micron, s.get_density())
plt.tight_layout()
../_images/d41bcce118157e88ea25a5b513f3c4bb7222ceeeed0b3bff0ed3360d5350869a.png

right=True#

plt.figure(figsize=(15, 2))
grid = MPLGrid(direction="right", share=True, right=True)
for s in states:
    ax = grid.next()
    ax.plot(s.xyz[0] / u.micron, s.get_density())
plt.tight_layout()
../_images/43ffc209cad4b6e3b633818f627ad990b4e597698d35ca1f52b3fa8059c0309f.png

grid()#

More complex layouts can be created using subgrids:

plt.figure(figsize=(10, 3))
grid = MPLGrid(direction="down", share=True)
for s in states[::3]:
    ax = grid.next(size=1.0 / 3)  # Make these 1/3 of the size
    ax.plot(s.xyz[0] / u.micron, s.get_density())
subgrid = grid.grid(size=1, direction="right", share=True)
for s in states:
    ax = subgrid.next(2)
    ax.plot(s.xyz[0] / u.micron, s.get_density())

plt.tight_layout()
../_images/53a93f4a9f2001ea1d0c4f8c9518b42a4ac05ebe8ea2fbc756b0500ca846d07d.png

Note in this case that we obscure the x-axis of the upper plots. This is a limitation of the current MPLGrid class - all axes must either be shared or not shared. To add a space, the first three panes should be in their own subgrid:

reload(gpe.plot_utils)
from gpe.plot_utils import MPLGrid
from matplotlib.gridspec import GridSpecFromSubplotSpec

plt.figure(figsize=(10, 3))
grid = MPLGrid(direction="down", share=False, space=0.5)
subgrid = grid.grid(direction="down", share=True)
for s in states[::3]:
    ax = subgrid.next(1.0 / 2)  # Make these 1/2 of the size
    ax.plot(s.xyz[0] / u.micron, s.get_density())
ax.set_xlabel("x")

subgrid = grid.grid(
    direction="right", share=True, space=0.1
)  # Some space might help lables not clash
for s in states:
    ax = subgrid.next(2)
    ax.plot(s.xyz[0] / u.micron, s.get_density())

plt.tight_layout()
../_images/c6ceec7f30594d8c76c27f1b88dc7f8ba230c52d1fa482c4aae20f85acb557ce.png

Note that tight_layout() does not work properly here. Not sure why. Probably the solution is to use the new constrained layout feature of matplotlib once it is settled.