3 from __future__ import division
12 # Step 1: make this file executable
14 # chmod +x plot_image.py
16 # Step 2: pipe data in python script
18 # ./gen_data | ./plot_image -s nx ny -c nc -t 'image title'
20 # with optional arguments
21 # -s nx ,ny image size [16x16]
22 # -c nc number of contour levels [none]
23 # -t ' ' image title ['some like it hot']
25 # additional: -g gray map [jet map]
28 # ref: matplotlib web site
29 # Michel Vallieres, 2007
32 # dummy function to initialize Z
40 mytitle = 'Some like it hot'
43 # parse command line arguments
47 if sys.argv[i].find("s") == 1:
48 nx = int( sys.argv[i+1] )
49 ny = int( sys.argv[i+2] )
51 elif sys.argv[i].find("c") == 1:
52 mycontours = int( sys.argv[i+1] )
54 elif sys.argv[i].find("t") == 1:
55 mytitle = sys.argv[i+1]
57 elif sys.argv[i].find("g") == 1:
59 elif sys.argv[i].find("h") == 1:
62 print " Syntax: script -s nx ny -c "
67 print "Title: ", mytitle
68 print "Image size: ", nx, ny
69 print "# countour lines: ", mycontours
76 X,Y = meshgrid( x, y )
95 print "Data range: ", min_data, max_data
99 im = imshow( Z, interpolation='bilinear', origin='lower',
100 cmap=mymap, extent=(1,nx-1.0,1,ny-1.0) )
104 dcont = ( max_data - min_data ) / ( mycontours - 1 )
105 cset = contour( Z, arange(min_data,max_data,dcont),
108 extent=(0,nx-1,0,ny-1)
111 clabel( cset, inline=1, fmt='%1.1f', fontsize=10 )