-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot2d.py
71 lines (51 loc) · 1.89 KB
/
plot2d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
import scipy.interpolate as interpol
values = np.loadtxt("2d-na068-linear-a1.tsv")
# Coordinates
xx = values[:,0].flatten()
zz = values[:,2].flatten()
# Forces
ux = values[:,3].flatten()
uz = values[:,5].flatten()
# Add the counter-propagating beams
# Add the negative x coordinates (for a symmetric plot)
xx = np.hstack([xx, -xx])
zz = np.hstack([zz, zz])
ux = np.hstack([ux, -ux])
uz = np.hstack([uz, uz])
#norms = np.sqrt(uz**2 + ux**2)
#ux = 15*ux/norms
#uz = 15*uz/norms
### Only take every nth row
#n = 4
#plt.quiver(zz[::n], xx[::n], uz[::n], ux[::n], norms[::n], cmap=cm.seismic, scale=400)
#plt.colorbar()
#plt.show()
#coords = np.vstack([zz,xx]).transpose()
#vals = np.vstack([uz,ux]).transpose()
zi = np.linspace(zz.min(), zz.max(), 100)
xi = np.linspace(xx.min(), xx.max(), 100)
ipts_z, ipts_x = np.meshgrid(zi, xi)
ux_int = interpol.griddata((zz, xx), ux, (ipts_z, ipts_x), method='cubic').reshape(len(xi), len(zi))
uz_int = interpol.griddata((zz, xx), uz, (ipts_z, ipts_x), method='cubic').reshape(len(xi), len(zi))
# Enable counter-propagating setup
#uz_int = 0.5*(uz_int - uz_int[:,::-1])
speed = np.sqrt(ux_int**2 + uz_int**2)
lw = 5*speed/speed.max()
fig = plt.figure(figsize=(7*(4/3), 7))
plt.streamplot(ipts_z, ipts_x, uz_int, ux_int, # data
color=speed, # array that determines the colour
cmap=cm.cool, # colour map
linewidth=lw, # line thickness
arrowstyle='->', # arrow style
arrowsize=1.5) # arrow size
#plt.colorbar() # add colour bar on the right
plt.title('Fuerzas en pinzas unipropagantes')
plt.xlabel("Z")
plt.ylabel("X")
plt.xlim([zi.min(), zi.max()])
plt.ylim([xi.min(), xi.max()])
plt.savefig("2d-solo.png", bbox_inches="tight", transparent=True)
plt.show()