-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.py
62 lines (46 loc) · 1.5 KB
/
draw.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
import sys
import math
import cairo
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import scipy.sparse
sys.stderr.write("Loading data...\n")
A = np.loadtxt(sys.argv[1]+".vi", delimiter=',')
ent = np.loadtxt(sys.argv[1]+".ent")
dimred = np.loadtxt(sys.argv[1]+".dimred")
n_seqs = np.size(ent,0)
# drawing
WIDTH=3840
HEIGHT=2160
sys.stderr.write("Creating %dx%d image...\n" % (WIDTH, HEIGHT))
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context (surface)
xmin, xmax = min(dimred[:,0]), max(dimred[:,0])
ymin, ymax = min(dimred[:,1]), max(dimred[:,1])
w,h = xmax-xmin, ymax-ymin
ctx.move_to( 0., 0.)
ctx.line_to( 0., HEIGHT)
ctx.line_to(WIDTH, HEIGHT)
ctx.line_to(WIDTH, 0.)
ctx.line_to( 0., 0.)
ctx.set_source_rgba(0.,0.,0.,1.)
ctx.fill()
scale = min(WIDTH/w, HEIGHT/h) * 0.95
ctx.scale(scale, scale)
tx,ty = (-xmin-xmax+WIDTH/scale)/2., (-ymin-ymax+HEIGHT/scale)/2.
ctx.translate(tx, ty)
cm = plt.cm.get_cmap('gist_rainbow') # colormap for for nodes/edges based on index
sys.stderr.write("Drawing nodes...\n")
cr.select_font_face("Inconsolata", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
cr.set_font_size(8)
for i in range(n_seqs):
x,y = dimred[i,:]
w = ent[i]/(80./9.) + 0.1
ctx.arc(x,y,NODE_SIZE*(0.5+ent[i]*0.5/8.),0, 2 * math.pi)
r,g,b,_ = cm(float(i)/n_seqs)
ctx.set_source_rgba(r,g,b, w)
ctx.fill()
sys.stderr.write("Saving...\n")
surface.write_to_png(sys.argv[2])
sys.stderr.write("Done.\n")