-
Notifications
You must be signed in to change notification settings - Fork 3
/
uberplot.py
63 lines (45 loc) · 1.66 KB
/
uberplot.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
import sys
import argparse
import matplotlib.pyplot as plot
from matplotlib.path import Path
import matplotlib.patches as patches
import utils
def parse_segments( filename ):
segments = []
with open( filename ) as fd:
for line in fd:
edge = [ float(i) for i in line.split() ]
if len(edge) == 4:
start = (edge[0],edge[1])
end = (edge[2],edge[3])
segments.append( (start,end) )
return segments
def plot_segments( ax, segments, **kwargs ):
for start,end in segments:
verts = [start,end,(0,0)]
codes = [Path.MOVETO,Path.LINETO,Path.STOP]
path = Path(verts, codes)
patch = patches.PathPatch(path, facecolor='none', **kwargs )
ax.add_patch(patch)
def scatter_segments( ax, segments, **kwargs ):
xy = [ ((i[0],j[0]),(i[1],j[1])) for (i,j) in segments]
x = [i[0] for i in xy]
y = [i[1] for i in xy]
ax.scatter( x,y, s=20, marker='o', **kwargs)
def scatter_points( ax, points, **kwargs ):
x = [i[0] for i in points]
y = [i[1] for i in points]
# ax.scatter( x,y, s=20, marker='o', **kwargs)
ax.scatter( x,y, marker='o', **kwargs)
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-s', "--segments", default=[None], action='store', type=str, nargs='*')
args = parser.parse_args()
fig = plot.figure()
ax = fig.add_subplot(111)
if args.segments != [None]:
for filename in args.segments:
seg = parse_segments(filename)
scatter_segments( ax, seg, edgecolor="red" )
plot_segments( ax, seg, edgecolor="blue" )
plot.show()