Changeset 578


Ignore:
Timestamp:
10/05/12 13:34:33 (4 years ago)
Author:
mmckerns
Message:

added wiggle room ('shortness' gap) for cones in scenario plotter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mystic/scripts/support_hypercube_scenario.py

    r575 r578  
    102102 
    103103#### plotting the cones #### 
    104 def plot_bowtie(ax, data, slope, bounds, color='0.75', axis=None): 
     104def plot_bowtie(ax, data, slope, bounds, color='0.75', axis=None, tol=0.0): 
     105  """plot (2D) double cones for a given dataset 
     106 
     107  ax -- matplotlib 'Axes3D' plot object 
     108  data -- list of datapoints, where datapoints are 3-tuples (i.e. x,y,z) 
     109  slope -- slope multiplier for cone on the X,Y,Z axes (for mesh construction) 
     110  bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 
     111  color -- string name (or rbg value) of color to use for datapoints 
     112  axis -- the axis of the cone 
     113  tol -- distance between center of mass of the double cones and a cone vertex 
     114""" 
    105115  if axis not in range(len(bounds)-1): return ax 
    106116  from numpy import asarray, inf 
    107117  data = asarray(data) 
    108118  sl = slope[axis] 
     119  gap = max(0., tol) 
     120  # find the endpoints of the cone:  y = slope * (x0 - x) + y0 
    109121  ylo = sl * (bounds[0][0] - data.T[0]) + data.T[1] 
    110122  yhi = sl * (bounds[0][1] - data.T[0]) + data.T[1] 
     
    117129 
    118130  for pt,yl,yu,zl,zu in zip(data,ylo,yhi,zlo,zhi): 
    119    #ax.plot([xlb,pt[0],xub], [yl,pt[1],yu], color='black') 
    120    #ax.plot([xlb,pt[0],xub], [zu,pt[1],zl], color='black') 
    121     ax.fill_between([xlb,pt[0],xub], [ylb]*3, [yl,pt[1],zl], \ 
     131   #ax.plot([xlb, pt[0], xub], [yl, pt[1], yu], color='black') 
     132   #ax.plot([xlb, pt[0], xub], [zu, pt[1], zl], color='black') 
     133    ax.fill_between([xlb, pt[0], xub], [ylb]*3, [yl-gap, pt[1]-gap, zl-gap], \ 
    122134                                     facecolor=color, alpha=0.2) 
    123     ax.fill_between([xlb,pt[0],xub], [yub]*3, [zu,pt[1],yu], \ 
     135    ax.fill_between([xlb, pt[0], xub], [yub]*3, [zu+gap, pt[1]+gap, yu+gap], \ 
    124136                                     facecolor=color, alpha=0.2) 
    125137  return ax 
    126138 
    127 def plot_cones(ax, data, slope, bounds, color='0.75', axis=None, strict=True): 
    128   """plot double cones for a given dataset 
     139def plot_cones(ax, data, slope, bounds, color='0.75', axis=None, strict=True, tol=0.0): 
     140  """plot (3D) double cones for a given dataset 
    129141 
    130142  ax -- matplotlib 'Axes3D' plot object 
     
    134146  color -- string name (or rbg value) of color to use for datapoints 
    135147  axis -- the axis of the cone 
    136 """ 
     148  tol -- distance between center of mass of the double cones and a cone vertex 
     149""" 
     150  from numpy import asarray, zeros 
    137151  # adjust slope, bounds, and data so cone axis is last  
    138152  slope = swap(slope, axis)  
     
    140154  data = [swap(pt,axis) for pt in data] 
    141155  cone = cone_builder(slope, bounds, strict=strict) 
     156  # prepare to apply the 'gap' tolerance 
     157  gap = zeros(len(slope)) 
     158  gap[-1:] = [max(0., tol)] #XXX: bad behavior if len(slope) is 0 
    142159  # plot the upper and lower cone 
    143160  for datapt in data: 
    144     _cone = cone(datapt, top=True) 
     161    datapt = asarray(datapt) 
     162    _cone = cone(datapt + gap, top=True) 
    145163    if _cone: 
    146164      X,Z,Y = swap(_cone, axis) # 'unswap' the axes 
    147165      ax.plot_surface(X, Y,Z, rstride=1, cstride=1, color=color, \ 
    148166                                         linewidths=0, alpha=.1) 
    149     _cone = cone(datapt, top=False) 
     167    _cone = cone(datapt - gap, top=False) 
    150168    if _cone: 
    151169      X,Z,Y = swap(_cone, axis) # 'unswap' the axes 
     
    278296                    metavar="INT",default=1.0, 
    279297                    help="grayscale contrast multiplier for points in plot") 
     298  parser.add_option("-g","--gap",action="store",dest="gap",\ 
     299                    metavar="INT",default=0.0, 
     300                    help="distance from double cone center to cone vertex") 
    280301  parser.add_option("-o","--data",action="store_true",dest="legacy",\ 
    281302                    default=False,help="plot legacy data, if provided") 
     
    380401    scale = 1.0 # color = color**scale 
    381402 
     403  try: # gap between double cone center and cone vertex 
     404    gap = float(parsed_opts.gap) 
     405  except: 
     406    gap = 0.0 
     407 
     408  _2D = False # if False, use 3D plots; if True, use 3D plots 
    382409  _2D = False # if False, use 3D plots; if True, use 3D plots 
    383410  cs = None 
     
    489516  if cones and data and xs in range(len(bounds)): 
    490517    if _2D: 
    491       plot_bowtie(ax1,coords,slope,bounds,axis=axis) 
     518      plot_bowtie(ax1,coords,slope,bounds,axis=axis,tol=gap) 
    492519    else: 
    493       plot_cones(ax1,coords,slope,bounds,axis=axis,strict=strict) 
     520      plot_cones(ax1,coords,slope,bounds,axis=axis,strict=strict,tol=gap) 
    494521  if legacy and data: 
    495522    plot_data(ax1,coords,bounds,strict=strict) 
     
    512539      if cones and data and xs in range(len(bounds)): 
    513540        if _2D: 
    514           exec "plot_bowtie(ax%d,coords,slope,bounds,axis=axis)" % i 
     541          exec "plot_bowtie(ax%d,coords,slope,bounds,axis=axis,tol=gap)" % i 
    515542        else: 
    516           exec "plot_cones(ax%d,coords,slope,bounds,axis=axis,strict=strict)" % i 
     543          exec "plot_cones(ax%d,coords,slope,bounds,axis=axis,strict=strict,tol=gap)" % i 
    517544      if legacy and data: 
    518545        exec "plot_data(ax%d,coords,bounds,strict=strict)" % i 
Note: See TracChangeset for help on using the changeset viewer.