Changeset 578
- Timestamp:
- 10/05/12 13:34:33 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/scripts/support_hypercube_scenario.py
r575 r578 102 102 103 103 #### plotting the cones #### 104 def plot_bowtie(ax, data, slope, bounds, color='0.75', axis=None): 104 def 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 """ 105 115 if axis not in range(len(bounds)-1): return ax 106 116 from numpy import asarray, inf 107 117 data = asarray(data) 108 118 sl = slope[axis] 119 gap = max(0., tol) 120 # find the endpoints of the cone: y = slope * (x0 - x) + y0 109 121 ylo = sl * (bounds[0][0] - data.T[0]) + data.T[1] 110 122 yhi = sl * (bounds[0][1] - data.T[0]) + data.T[1] … … 117 129 118 130 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], \ 122 134 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], \ 124 136 facecolor=color, alpha=0.2) 125 137 return ax 126 138 127 def plot_cones(ax, data, slope, bounds, color='0.75', axis=None, strict=True ):128 """plot double cones for a given dataset139 def 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 129 141 130 142 ax -- matplotlib 'Axes3D' plot object … … 134 146 color -- string name (or rbg value) of color to use for datapoints 135 147 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 137 151 # adjust slope, bounds, and data so cone axis is last 138 152 slope = swap(slope, axis) … … 140 154 data = [swap(pt,axis) for pt in data] 141 155 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 142 159 # plot the upper and lower cone 143 160 for datapt in data: 144 _cone = cone(datapt, top=True) 161 datapt = asarray(datapt) 162 _cone = cone(datapt + gap, top=True) 145 163 if _cone: 146 164 X,Z,Y = swap(_cone, axis) # 'unswap' the axes 147 165 ax.plot_surface(X, Y,Z, rstride=1, cstride=1, color=color, \ 148 166 linewidths=0, alpha=.1) 149 _cone = cone(datapt , top=False)167 _cone = cone(datapt - gap, top=False) 150 168 if _cone: 151 169 X,Z,Y = swap(_cone, axis) # 'unswap' the axes … … 278 296 metavar="INT",default=1.0, 279 297 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") 280 301 parser.add_option("-o","--data",action="store_true",dest="legacy",\ 281 302 default=False,help="plot legacy data, if provided") … … 380 401 scale = 1.0 # color = color**scale 381 402 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 382 409 _2D = False # if False, use 3D plots; if True, use 3D plots 383 410 cs = None … … 489 516 if cones and data and xs in range(len(bounds)): 490 517 if _2D: 491 plot_bowtie(ax1,coords,slope,bounds,axis=axis )518 plot_bowtie(ax1,coords,slope,bounds,axis=axis,tol=gap) 492 519 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) 494 521 if legacy and data: 495 522 plot_data(ax1,coords,bounds,strict=strict) … … 512 539 if cones and data and xs in range(len(bounds)): 513 540 if _2D: 514 exec "plot_bowtie(ax%d,coords,slope,bounds,axis=axis )" % i541 exec "plot_bowtie(ax%d,coords,slope,bounds,axis=axis,tol=gap)" % i 515 542 else: 516 exec "plot_cones(ax%d,coords,slope,bounds,axis=axis,strict=strict )" % i543 exec "plot_cones(ax%d,coords,slope,bounds,axis=axis,strict=strict,tol=gap)" % i 517 544 if legacy and data: 518 545 exec "plot_data(ax%d,coords,bounds,strict=strict)" % i
Note: See TracChangeset
for help on using the changeset viewer.