tomwalters@381
|
1 #!/usr/bin/env python
|
tomwalters@381
|
2 """
|
tomwalters@381
|
3 spider_plot.py
|
tomwalters@381
|
4
|
tomwalters@381
|
5 Created by Thomas Walters on 2010-09-12.
|
tomwalters@381
|
6 """
|
tomwalters@381
|
7
|
tomwalters@382
|
8 import sys
|
tomwalters@382
|
9 import getopt
|
tomwalters@391
|
10 import matplotlib as mpl
|
tomwalters@392
|
11 mpl.use('PDF')
|
tomwalters@381
|
12 import numpy as np
|
tomwalters@381
|
13 import pylab as p
|
tomwalters@381
|
14 import mpl_toolkits.mplot3d.axes3d as p3
|
tomwalters@381
|
15 from matplotlib import cm
|
tomwalters@381
|
16 import matplotlib.ticker as ticker
|
tomwalters@381
|
17
|
tomwalters@382
|
18 help_message = '''
|
tomwalters@382
|
19 Plot the spider.
|
tomwalters@381
|
20
|
tomwalters@382
|
21 Arguments:
|
tomwalters@382
|
22 -i --input_file
|
tomwalters@382
|
23 -o --output_file
|
tomwalters@382
|
24 '''
|
tomwalters@381
|
25
|
tomwalters@382
|
26 class Usage(Exception):
|
tomwalters@382
|
27 def __init__(self, msg):
|
tomwalters@382
|
28 self.msg = msg
|
tomwalters@381
|
29
|
tomwalters@381
|
30
|
tomwalters@382
|
31 def main(argv=None):
|
tomwalters@382
|
32 if argv is None:
|
tomwalters@382
|
33 argv = sys.argv
|
tomwalters@382
|
34 try:
|
tomwalters@382
|
35 try:
|
tomwalters@382
|
36 opts, args = getopt.getopt(argv[1:], "hi:o:",
|
tomwalters@382
|
37 ["help", "input_file=", "output_file="])
|
tomwalters@382
|
38 except getopt.error, msg:
|
tomwalters@382
|
39 raise Usage(msg)
|
tomwalters@382
|
40
|
tomwalters@382
|
41 # defaults
|
tomwalters@382
|
42 input_file = "results_iteration_15.txt"
|
tomwalters@392
|
43 output_file = "results_iteration_15.png"
|
tomwalters@382
|
44
|
tomwalters@382
|
45 # option processing
|
tomwalters@382
|
46 for option, value in opts:
|
tomwalters@382
|
47 if option in ("-h", "--help"):
|
tomwalters@382
|
48 raise Usage(help_message)
|
tomwalters@382
|
49 if option in ("-i", "--input_file"):
|
tomwalters@382
|
50 input_file = value
|
tomwalters@382
|
51 if option in ("-o", "--output_file"):
|
tomwalters@382
|
52 output_file = value
|
tomwalters@382
|
53
|
tomwalters@382
|
54 except Usage, err:
|
tomwalters@382
|
55 print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
|
tomwalters@382
|
56 print >> sys.stderr, "\t for help use --help"
|
tomwalters@382
|
57 return 2
|
tomwalters@390
|
58
|
tomwalters@390
|
59 central_vtl=15
|
tomwalters@390
|
60 central_vtl_scaling=112.32
|
tomwalters@390
|
61
|
tomwalters@382
|
62 # Read in a file with lines in the form
|
tomwalters@382
|
63 # Pitch Scale Percentage
|
tomwalters@382
|
64 xs=[]
|
tomwalters@382
|
65 ys=[]
|
tomwalters@382
|
66 zs=[]
|
tomwalters@382
|
67 f = open(input_file, 'r')
|
tomwalters@382
|
68 for line in f:
|
tomwalters@382
|
69 if line[0] != "#":
|
tomwalters@382
|
70 values = line.strip().split(' ')
|
tomwalters@382
|
71 xs.append(central_vtl*central_vtl_scaling/float(values[1]))
|
tomwalters@382
|
72 ys.append(float(values[0]))
|
tomwalters@382
|
73 zs.append(float(values[2]))
|
tomwalters@381
|
74
|
tomwalters@381
|
75
|
tomwalters@382
|
76 # Define a tiny sphere, centered on the origin, which
|
tomwalters@382
|
77 # we'll shift to the desired position.
|
tomwalters@382
|
78 u=np.r_[0:2*np.pi:50j]
|
tomwalters@382
|
79 v=np.r_[0:np.pi:50j]
|
tomwalters@382
|
80 sx=0.01*np.outer(np.cos(u),np.sin(v))
|
tomwalters@382
|
81 sy=0.01*np.outer(np.sin(u),np.sin(v))
|
tomwalters@382
|
82 sz=2.5*np.outer(np.ones(np.size(u)),np.cos(v))
|
tomwalters@381
|
83
|
tomwalters@382
|
84 fig=p.figure()
|
tomwalters@382
|
85 ax = p3.Axes3D(fig, azim=-80, elev=60)
|
tomwalters@381
|
86
|
tomwalters@382
|
87 colormap = cm.get_cmap('jet', 100)
|
tomwalters@381
|
88
|
tomwalters@382
|
89 # Note: here I fake out the lack of proper logarihmic scales on 3D axes in
|
tomwalters@382
|
90 # matplotlib by just plotting log values on a linear scale and renaming
|
tomwalters@382
|
91 # the labels.
|
tomwalters@382
|
92 # (This doesn't work: ax.w_yaxis.set_scale('log') ax.w_xaxis.set_scale('log'))
|
tomwalters@381
|
93
|
tomwalters@382
|
94 # Plot the values seven at a time as dark lines.
|
tomwalters@382
|
95 # These are the individual spokes of the spoke pattern.
|
tomwalters@382
|
96 n=7
|
tomwalters@382
|
97 for i in xrange(0,8):
|
tomwalters@382
|
98 ax.plot(np.log(xs[i*n:(i+1)*n]), np.log(ys[i*n:(i+1)*n]), zs[i*n:(i+1)*n], color=[0,0,0])
|
tomwalters@381
|
99
|
tomwalters@382
|
100 for x,y,z in zip(xs,ys,zs):
|
tomwalters@382
|
101 ax.plot(np.log([x, x]), np.log([y, y]), [z, 0], color=[0.8,0.8,0.8])
|
tomwalters@382
|
102 ax.plot_surface(sx+np.log(x),sy+np.log(y),sz+z, color=colormap(int(z)), linewidth=0)
|
tomwalters@381
|
103
|
tomwalters@382
|
104 ax.set_ylabel('GPR/Hz')
|
tomwalters@382
|
105 ax.set_xlabel('VTL/cm')
|
tomwalters@382
|
106 ax.set_zlabel('Percent correct')
|
tomwalters@382
|
107 ax.set_ylim3d(np.log([131,225]))
|
tomwalters@382
|
108 ax.set_xlim3d(np.log([9.9, 22.1]))
|
tomwalters@382
|
109 ax.set_zlim3d([-1, 101])
|
tomwalters@382
|
110 ax.w_zaxis.set_major_locator(ticker.FixedLocator([0, 20, 40, 60, 80, 100]))
|
tomwalters@381
|
111
|
tomwalters@382
|
112 ax.w_xaxis.set_major_locator(ticker.FixedLocator(np.log([10,15,22])))
|
tomwalters@382
|
113 ax.w_xaxis.set_ticklabels(['10', '15', '22'])
|
tomwalters@382
|
114 ax.w_yaxis.set_major_locator(ticker.FixedLocator(np.log([132, 172, 224])))
|
tomwalters@382
|
115 ax.w_yaxis.set_ticklabels(['132', '172', '224'])
|
tomwalters@381
|
116
|
tomwalters@382
|
117 #for a in ax.w_xaxis.get_ticklines()+ax.w_xaxis.get_ticklabels():
|
tomwalters@382
|
118 # a.set_visible(False)
|
tomwalters@381
|
119
|
tomwalters@382
|
120 #for a in ax.w_yaxis.get_ticklines()+ax.w_yaxis.get_ticklabels():
|
tomwalters@382
|
121 # a.set_visible(False)
|
tomwalters@382
|
122
|
tomwalters@382
|
123
|
tomwalters@382
|
124 #p.show()
|
tomwalters@392
|
125 p.savefig(output_file)
|
tomwalters@382
|
126
|
tomwalters@389
|
127 if __name__ == "__main__":
|
tomwalters@392
|
128 sys.exit(main())
|