Changeset 565 for branches


Ignore:
Timestamp:
09/20/12 14:55:38 (4 years ago)
Author:
mmckerns
Message:

enable toggle between 'expected' coord alignment and values-last alignment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/UQ/math/legacy/plot_data.py

    r564 r565  
    9797 
    9898#### plotting the cones #### 
    99 def plot_cones(ax, data, slope, bounds, color='0.75', axis=-1): 
     99def plot_cones(ax, data, slope, bounds, color='0.75', axis=None): 
    100100  """plot double cones for a given dataset 
    101101 
     
    116116    _cone = cone(datapt, top=True) 
    117117    if _cone: 
    118       X,Z,Y = swap(_cone, xs) # 'unswap' the axes 
    119       ax.plot_surface(X, Z,Y, rstride=1, cstride=1, color=color)  
     118      X,Z,Y = swap(_cone, axis) # 'unswap' the axes 
     119      ax.plot_surface(X, Y,Z, rstride=1, cstride=1, color=color)  
    120120    _cone = cone(datapt, top=False) 
    121121    if _cone: 
    122       X,Z,Y = swap(_cone, xs) # 'unswap' the axes 
    123       ax.plot_surface(X, Z,Y, rstride=1, cstride=1, color=color) 
     122      X,Z,Y = swap(_cone, axis) # 'unswap' the axes 
     123      ax.plot_surface(X, Y,Z, rstride=1, cstride=1, color=color) 
    124124  return ax 
    125125 
    126 def plot_data(ax, data, bounds, color='red', axis=-1): 
     126def plot_data(ax, data, bounds, color='red'): 
    127127  """plot datapoints for a given dataset 
    128128 
     
    131131  bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 
    132132  color -- string name (or rbg value) of color to use for datapoints 
    133   axis -- the axis of the cone 
    134133""" 
    135134  strict = True # always respect the bounds 
     
    144143      pass  # don't plot if datapt is out of bounds 
    145144    else: 
    146       ax.plot([datapt[0]], [datapt[2]], [datapt[1]], \ 
     145      ax.plot([datapt[0]], [datapt[1]], [datapt[2]], \ 
    147146              color=color, marker='o', markersize=10) 
    148147  return ax 
     
    157156  # plot only within [lb,ub] 
    158157  ax.set_xlim3d(lb[0], ub[0]) 
    159   ax.set_zlim3d(lb[1], ub[1]) 
    160   ax.set_ylim3d(lb[2], ub[2]) # cone "center" axis 
     158  ax.set_ylim3d(lb[1], ub[1]) 
     159  ax.set_zlim3d(lb[2], ub[2]) # cone "center" axis 
    161160  return ax 
    162161 
     
    168167""" 
    169168  ax.set_xlabel(labels[0]) 
    170   ax.set_zlabel(labels[1]) 
    171   ax.set_ylabel(labels[2]) # cone "center" axis 
     169  ax.set_ylabel(labels[1]) 
     170  ax.set_zlabel(labels[2]) # cone "center" axis 
    172171  return ax 
    173172 
     
    189188  return coords, slope 
    190189 
    191 def reduce(alist, axis=-1): 
    192   """ reduce a n-member list to a (n-1)-member list 
    193  
    194   alist -- a list 
    195   axis -- selected member (an int) to remove 
     190def swap(alist, index=None): 
     191  """ swap the selected list element with the last element in alist 
     192 
     193  alist -- a list of objects 
     194  index -- the selected element 
    196195  """ 
    197   if axis not in range(len(alist[:-1])):  # reduce the last axis 
    198     return alist[:-1]  
    199   return alist[:axis] + alist[axis+1:] 
    200  
    201 def swap(alist, axis=-1): 
    202   if axis not in range(len(alist)):  # don't swap an axis 
     196  if index not in range(len(alist)):  # don't swap an element 
    203197    return alist  
    204   return alist[:axis] + alist[axis+1:] + alist[axis:axis+1] 
     198  return alist[:index] + alist[index+1:] + alist[index:index+1] 
    205199 
    206200 
     
    223217                    metavar="INT",default=None, 
    224218                    help="id # of axis to plot values NOT coords") 
     219  parser.add_option("-v","--vertical",action="store_true",dest="vertical",\ 
     220                    default=False,help="always plot cones on vertical axis") 
    225221  parsed_opts, parsed_args = parser.parse_args() 
    226222 
     
    262258    xs = None # don't plot values; plot values on 'x' axis with xs = 0 
    263259 
     260  try: # always plot cones on vertical axis 
     261    vertical_cones = parsed_opts.vertical 
     262  except: 
     263    vertical_cones = False 
     264 
    264265  # ensure all terms of bounds and xyz are tuples 
    265266  for bound in bounds: 
     
    273274 
    274275  # get coords (and values) for selected axes 
    275   coords, slope = get_coords(data, xs)  #FIXME: requires Y-value to be last 
     276  coords, slope = get_coords(data, xs) 
    276277  print "bounds: %s" % bounds 
    277278  print "slope: %s" % slope 
     
    290291  ax = Axes3D(fig)#,aspect='equal')  
    291292  if xs in range(len(bounds)):  # we are replacing an axis 
     293    if vertical_cones: 
     294      # adjust slope, bounds, and data so cone axis is last  
     295      slope = swap(slope, xs)  
     296      bounds = swap(bounds, xs)  
     297      coords = [swap(pt,xs) for pt in coords] 
     298      label = swap(label, xs) 
     299      xs = None 
    292300    plot_cones(ax, coords, slope, bounds, axis=xs) 
    293   plot_data(ax, coords, bounds, axis=xs) 
     301  plot_data(ax, coords, bounds) 
    294302 #clip_axes(ax, bounds) 
    295303  label_axes(ax, label) 
Note: See TracChangeset for help on using the changeset viewer.