tools/plot-values/plot.py
author Dmitriy Morozov <dmitriy@mrzv.org>
Thu Jul 09 02:42:47 2009 -0700 (2 years ago)
branchdev
changeset 138 96030f8d2f2c
child 141cda0b85ffc50
permissions -rwxr-xr-x
Rips pairwise cohomology produces output necessary for 1-cocycle parametrization
     1 #!/usr/bin/env python
     2 
     3 from    pylab           import scatter, show, cm, colorbar, savefig, axis, \
     4                                figure, xlim, axes, hsv, subplots_adjust as adjust
     5 from    itertools       import izip
     6 from    sys             import argv, exit
     7 import  os.path         as     osp
     8 
     9 
    10 def plot(val_fn, pts_fn, output_fn):
    11     points = []
    12     with open(pts_fn) as fp:
    13         for line in fp.xreadlines():
    14             points.append(map(float, line.split()))
    15     
    16     values = []
    17     with open(val_fn) as fp:
    18         for line in fp.xreadlines():
    19             values.append(float(line.split()[1]))
    20 
    21     xx = [pt[0] for pt in points]
    22     yy = [pt[1] for pt in points]
    23     print "X:", min(xx), max(xx)
    24     print "Y:", min(yy), max(yy)
    25 
    26     m = min(values)
    27     values = [(v-m) % 1. for v in values]
    28     print "V:", min(values), max(values)
    29 
    30     aspect = (max(yy) - min(yy))/(max(xx) - min(xx)) + .1
    31     # aspect = .5
    32 
    33     # hsv()
    34     # fig = figure(figsize = (3,3*aspect))
    35     # ax = fig.add_axes([-.05,-.1,1.1,1.1])
    36     ax = axes()
    37     ax.set_axis_off()
    38     ax.set_aspect('equal', 'box')
    39     ax.scatter(xx,yy,s=10,c=values)
    40     # adjust(0,0,1,1,0,0)
    41     colorbar()
    42     fig.savefig(output_fn)
    43 
    44 if __name__ == '__main__':
    45     if len(argv) < 3:
    46         print "Usage: %s VALUES POINTS" % argv[0]
    47         exit()
    48 
    49     val_fn = argv[1]
    50     pts_fn  = argv[2]
    51     output_fn, ext = osp.splitext(val_fn)
    52     output_fn += '.pdf'
    53     plot(val_fn, pts_fn, output_fn)