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