-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_dat.py
66 lines (55 loc) · 2.07 KB
/
plot_dat.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
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import os
from traj_parser import *
DATA_FRAC = 5 # graph every nth data point
LINE_ONLY = True # plot only lines (not points) for trajectories
SCALE = 1e4 # scale the units
ASSUME_FILENAME = True # assume dat file is called 'pe-trajectories.dat'
DEFAULT_FILE = 'pe-trajectories.dat'
def plot_dat(trajectories=None, filename=None):
""" Plot a set of particle trajectories from pyPENELOPE
If a list of parsed trajectories or the filename of a .dat file to parse
is not specified, will prompt for a data filepath
args:
trajectories -- a list of trajectories to plot
filename -- path to a .dat file to parse
returns nothing
"""
if trajectories is None:
if filename is None:
if ASSUME_FILENAME:
if os.path.isfile(DEFAULT_FILE):
filename = DEFAULT_FILE
if filename is None:
print "current location: {}".format(os.getcwd())
filename = raw_input("Where is the .dat file?: ")
trajectories = parse_traj(filename, trim=True)
first = True
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
tracks = []
for traj in trajectories:
tracks.append([[], [], []])
for index, event in enumerate(traj.events):
event['x'] *= SCALE
event['y'] *= SCALE
event['z'] *= SCALE
color = 'r' if first else 'b'
if (index % 10 == 0 and not LINE_ONLY) or (first and LINE_ONLY):
ax.scatter(event['x'], event['y'], event['z'],
c=color, marker='o')
tracks[-1][0].append(event['x'])
tracks[-1][1].append(event['y'])
tracks[-1][2].append(event['z'])
first = False
for track in tracks:
ax.plot(track[0], track[1], track[2], zdir=track[2], c=color, alpha=0.4)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
plt.show()
if __name__ == '__main__':
plot_dat()