Initiate
This commit is contained in:
Executable
+82
@@ -0,0 +1,82 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""
|
||||
Plot the time-dependent density expectation value in Lieb-Liniger (n-hole wavepacket).
|
||||
|
||||
Setup:
|
||||
- ensure matplotlib and numpy are installed in your python environment
|
||||
- make this file executable (chmod +x multiplot_animated.py)
|
||||
|
||||
Usage: ./multiplot_animated.py [plot output filename] [1st rho file name] [2nd rho file name] ... [last rho file name]
|
||||
"""
|
||||
|
||||
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.animation as animation
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
argc = len(sys.argv) # The number of plot lines is argc-2
|
||||
|
||||
output_filename = str(sys.argv[1])
|
||||
|
||||
lines = []
|
||||
|
||||
for i in range(2,argc):
|
||||
filename = str(sys.argv[i])
|
||||
data = filename.rpartition('/')[2]
|
||||
data = data.partition('c_')[2]
|
||||
linedict = {}
|
||||
linedict["c"] = float(data.partition('_')[0])
|
||||
data = data.partition('N_')[2]
|
||||
linedict["N"] = int(data.partition('_')[0])
|
||||
linedict["L"] = float(linedict["N"])
|
||||
data = data.partition('nholes_')[2]
|
||||
linedict["nholes"] = int(data.partition('_')[0])
|
||||
data = data.partition('width_')[2]
|
||||
linedict["width"] = int(data.partition('_')[0])
|
||||
data = data.partition('offset_')[2]
|
||||
linedict["offset"] = int(data.partition('_')[0])
|
||||
data = data.partition('_')[2]
|
||||
linedict["protocol"] = data.partition('_Nx')[0]
|
||||
data = data.partition('tmax_')[2].partition('.rhoxt')[0]
|
||||
linedict["tmax"] = float(data.partition('_')[0])
|
||||
linedict["x"] = np.loadtxt(filename.replace('.rhoxt','.x'), unpack=True)
|
||||
linedict["Nx"] = linedict["x"].size
|
||||
linedict["rho"] = np.loadtxt(filename, unpack=True)
|
||||
linedict["Nt"] = int(linedict["rho"].size/linedict["rho"][0].size)
|
||||
linedict["dt"] = linedict["tmax"]/(linedict["Nt"]-1)
|
||||
lines.append(linedict)
|
||||
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
for line in lines:
|
||||
line["line"] = ax.plot(
|
||||
line["x"], line["rho"][0], '.', markersize=4,
|
||||
label=f"c={line['c']} N={line['N']} nh={line['nholes']} w={line['width']} o={line['offset']} {line['protocol']}"
|
||||
)[0]
|
||||
|
||||
ax.set(
|
||||
xlabel='x',
|
||||
ylabel=r'$\rho(x, t)$',
|
||||
title=f"Density expectation value")
|
||||
ax.legend(bbox_to_anchor=(0.05, -0.16), loc="upper left")
|
||||
plt.tight_layout()
|
||||
|
||||
time_text = fig.text(0.8, 0.15, f"t=0")
|
||||
|
||||
|
||||
def update(frame):
|
||||
for line in lines:
|
||||
line["line"].set_ydata(line["rho"][frame])
|
||||
time_text.set_text(f"t={frame*lines[0]['dt']}")
|
||||
return (lines, time_text)
|
||||
|
||||
|
||||
ani = animation.FuncAnimation(fig=fig, func=update, frames=lines[0]["Nt"], interval=100)
|
||||
|
||||
ani.save(output_filename + ".mp4")
|
||||
|
||||
plt.show()
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""
|
||||
Plot the time-dependent density expectation value in Lieb-Liniger (n-hole wavepacket).
|
||||
|
||||
Setup:
|
||||
- ensure matplotlib and numpy are installed in your python environment
|
||||
- make this file executable (chmod +x plot_animated.py)
|
||||
|
||||
Usage: ./plot_animated.py [rho file name]
|
||||
"""
|
||||
|
||||
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.animation as animation
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
filename = str(sys.argv[1])
|
||||
|
||||
data = filename.rpartition('/')[2]
|
||||
|
||||
data = data.partition('c_')[2]
|
||||
c = float(data.partition('_')[0])
|
||||
data = data.partition('N_')[2]
|
||||
N = int(data.partition('_')[0])
|
||||
L = float(N)
|
||||
data = data.partition('nholes_')[2]
|
||||
nholes = int(data.partition('_')[0])
|
||||
data = data.partition('width_')[2]
|
||||
width = int(data.partition('_')[0])
|
||||
data = data.partition('offset_')[2]
|
||||
offset = int(data.partition('_')[0])
|
||||
data = data.partition('tmax_')[2].partition('.rhoxt')[0]
|
||||
tmax = float(data.partition('_')[0])
|
||||
|
||||
|
||||
x = np.loadtxt(filename.replace('.rhoxt','.x'), unpack=True)
|
||||
|
||||
Nx = x.size
|
||||
|
||||
rho = np.loadtxt(filename, unpack=True)
|
||||
|
||||
Nt = int(rho.size/rho[0].size)
|
||||
dt = tmax/(Nt-1)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
artists = []
|
||||
|
||||
for i in range(Nt):
|
||||
container = ax.plot(x, rho[i], '.', markersize=4, color='blue')
|
||||
artists.append(container)
|
||||
|
||||
ani = animation.ArtistAnimation(fig=fig, artists=artists, interval=100)
|
||||
|
||||
plt.xlabel('x')
|
||||
plt.ylabel(r'$\rho(x, t)$')
|
||||
plt.title(f"Density expectation value\n{c=}, {N=}, nh={nholes}, w={width}, o={offset}")
|
||||
|
||||
ani.save(filename.replace("rhoxt", "mp4"))
|
||||
|
||||
plt.show()
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""
|
||||
Plot the t=0 density expectation value in Lieb-Liniger (n-hole wavepacket).
|
||||
|
||||
Setup:
|
||||
- ensure matplotlib and numpy are installed in your python environment
|
||||
- make this file executable (chmod +x plot_to.py)
|
||||
|
||||
Usage: ./plot_t0.py [rho file name]
|
||||
"""
|
||||
|
||||
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
filename = str(sys.argv[1])
|
||||
|
||||
x = np.loadtxt(filename.replace('.rhoxt','.x'), unpack=True)
|
||||
|
||||
rho = np.loadtxt(filename, usecols=(0), unpack=True)
|
||||
|
||||
plt.plot(x, rho, '.', markersize=4)
|
||||
|
||||
plt.xlabel('x')
|
||||
plt.ylabel(r'$\rho(x, t=0)$')
|
||||
plt.title('Density expectation value\n' + filename)
|
||||
|
||||
plt.savefig(filename.replace('.rhoxt', '.png'))
|
||||
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user