Skip to content

Commit 8842b41

Browse files
marcelsandoyubkim
authored andcommitted
Tool to visualize .xyz file format (#99)
* Tool to visualize .xyz file format * Some adjusts on xyz visualizer
1 parent 9e46c3f commit 8842b41

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

scripts/visualize_xyz.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
3+
import numpy as np
4+
import matplotlib
5+
matplotlib.use("Agg")
6+
import matplotlib.pyplot as plt
7+
import matplotlib.animation as animation
8+
import sys
9+
import utils
10+
11+
def render_frame(num, data, line):
12+
xyz_file = open(files[num])
13+
14+
_x = []
15+
_y = []
16+
17+
for xyz in xyz_file:
18+
_x.append(float(xyz.split()[0]))
19+
_y.append(float(xyz.split()[1]))
20+
21+
line.set_data(_x, _y)
22+
xyz_file.close()
23+
24+
return line,
25+
26+
# Simulation Path
27+
path = sys.argv[1]
28+
output_name = sys.argv[2] if len(sys.argv) >= 2 else 'result.mp4'
29+
files = utils.get_all_files(path, "*.xyz")
30+
size_files = len(files)
31+
32+
# Set up formatting for the movie files
33+
Writer = animation.writers['ffmpeg']
34+
writer = Writer(fps=25, bitrate=1800)
35+
36+
fig1 = plt.figure()
37+
38+
data = []
39+
l, = plt.plot([], [], 'ro')
40+
41+
plt.xlim(0, 1)
42+
plt.ylim(0, 1)
43+
plt.xlabel('x')
44+
plt.title('Simulation Result')
45+
46+
line_ani = animation.FuncAnimation(fig1, render_frame, size_files, fargs=(data, l),
47+
interval=50, blit=True)
48+
49+
line_ani.save(output_name, writer=writer)

0 commit comments

Comments
 (0)