-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
43 lines (39 loc) · 1.43 KB
/
Copy pathplot.py
File metadata and controls
43 lines (39 loc) · 1.43 KB
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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
def read_node_from_file(filename:str):
with open(filename, "r") as file:
lines = file.readlines()
tokens = lines[0].split()
nv = int(tokens[0])
xs, ys, ts = [], [], []
for line in lines[1:]:
tokens = line.split()
x, y = np.float64(tokens[1]), np.float64(tokens[2])
tag = int(tokens[3]) if len(tokens) > 3 else 0
xs.append(x)
ys.append(y)
ts.append(tag)
return np.array(xs), np.array(ys), np.array(ts, dtype=int)
color_map = mcolors.ListedColormap([
'red', 'blue', 'green', 'yellow', 'gray', 'black', 'cyan', 'orange', 'purple',
'lightgreen', 'magenta', 'brown', 'pink', 'olive'])
#color_map = mcolors.ListedColormap(mcolors.BASE_COLORS)
#color_map = mcolors.ListedColormap(mcolors.CSS4_COLORS)
#color_map = mcolors.ListedColormap(mcolors.XKCD_COLORS)
if __name__ == "__main__":
import sys
if len(sys.argv) == 2:
filename = sys.argv[1]
x, y, tag = read_node_from_file(filename)
x0, x1 = min(x), max(x)
y0, y1 = min(y), max(y)
s = max(x1 - x0, y1 - y0)
xc = (x0 + x1) * 0.5
yc = (y0 + y1) * 0.5
d = s * 0.6
plt.scatter(x, y, c=tag, cmap=color_map)
plt.axis('square')
plt.xlim(xc - d, xc + d)
plt.ylim(yc - d, yc + d)
plt.show()