tomwalters@381: #!/usr/bin/env python tomwalters@381: """ tomwalters@381: spider_plot.py tomwalters@381: tomwalters@381: Created by Thomas Walters on 2010-09-12. tomwalters@381: Copyright 2010 Google. All rights reserved. tomwalters@381: """ tomwalters@381: tomwalters@381: import numpy as np tomwalters@381: import pylab as p tomwalters@381: import mpl_toolkits.mplot3d.axes3d as p3 tomwalters@381: import matplotlib as mpl tomwalters@381: from matplotlib import cm tomwalters@381: import matplotlib.ticker as ticker tomwalters@381: tomwalters@381: total_value_count=185 tomwalters@381: tomwalters@381: central_vtl=15 tomwalters@381: central_vtl_scaling=112.32 tomwalters@381: tomwalters@381: # Read in a file with lines in the form tomwalters@381: # Pitch Scale Percentage tomwalters@381: xs=[] tomwalters@381: ys=[] tomwalters@381: zs=[] tomwalters@381: f = open('plottable_results.txt', 'r') tomwalters@381: for line in f: tomwalters@381: if line[0] != "#": tomwalters@381: values = line.strip().split(' ') tomwalters@381: xs.append(central_vtl*central_vtl_scaling/float(values[1])) tomwalters@381: ys.append(float(values[0])) tomwalters@381: zs.append(float(values[2])) tomwalters@381: tomwalters@381: tomwalters@381: # Define a tiny sphere, centered on the origin, which tomwalters@381: # we'll shift to the desired position. tomwalters@381: u=np.r_[0:2*np.pi:50j] tomwalters@381: v=np.r_[0:np.pi:50j] tomwalters@381: sx=0.01*np.outer(np.cos(u),np.sin(v)) tomwalters@381: sy=0.01*np.outer(np.sin(u),np.sin(v)) tomwalters@381: sz=2.5*np.outer(np.ones(np.size(u)),np.cos(v)) tomwalters@381: tomwalters@381: fig=p.figure() tomwalters@381: ax = p3.Axes3D(fig, azim=-80, elev=60) tomwalters@381: tomwalters@381: colormap = cm.get_cmap('jet', 100) tomwalters@381: tomwalters@381: # Note: here I fake out the lack of proper logarihmic scales on 3D axes in tomwalters@381: # matplotlib by just plotting log values on a linear scale and renaming tomwalters@381: # the labels. tomwalters@381: # (This doesn't work: ax.w_yaxis.set_scale('log') ax.w_xaxis.set_scale('log')) tomwalters@381: tomwalters@381: # Plot the values seven at a time as dark lines. tomwalters@381: # These are the individual spokes of the spoke pattern. tomwalters@381: n=7 tomwalters@381: for i in xrange(0,8): tomwalters@381: 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: tomwalters@381: for x,y,z in zip(xs,ys,zs): tomwalters@381: ax.plot(np.log([x, x]), np.log([y, y]), [z, 0], color=[0.8,0.8,0.8]) tomwalters@381: ax.plot_surface(sx+np.log(x),sy+np.log(y),sz+z, color=colormap(int(z)), linewidth=0) tomwalters@381: tomwalters@381: ax.set_ylabel('GPR/Hz') tomwalters@381: ax.set_xlabel('VTL/cm') tomwalters@381: ax.set_zlabel('Percent correct') tomwalters@381: ax.set_ylim3d(np.log([131,225])) tomwalters@381: ax.set_xlim3d(np.log([9.9, 22.1])) tomwalters@381: ax.set_zlim3d([-1, 101]) tomwalters@381: ax.w_zaxis.set_major_locator(ticker.FixedLocator([0, 20, 40, 60, 80, 100])) tomwalters@381: tomwalters@381: ax.w_xaxis.set_major_locator(ticker.FixedLocator(np.log([10,15,22]))) tomwalters@381: ax.w_xaxis.set_ticklabels(['10', '15', '22']) tomwalters@381: ax.w_yaxis.set_major_locator(ticker.FixedLocator(np.log([132, 172, 224]))) tomwalters@381: ax.w_yaxis.set_ticklabels(['132', '172', '224']) tomwalters@381: tomwalters@381: #for a in ax.w_xaxis.get_ticklines()+ax.w_xaxis.get_ticklabels(): tomwalters@381: # a.set_visible(False) tomwalters@381: tomwalters@381: #for a in ax.w_yaxis.get_ticklines()+ax.w_yaxis.get_ticklabels(): tomwalters@381: # a.set_visible(False) tomwalters@381: tomwalters@381: tomwalters@381: #p.show() tomwalters@381: p.savefig('results.png') tomwalters@381: