Changeset 574
- Timestamp:
- 10/03/12 15:27:58 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/scripts/support_hypercube_scenario.py
r573 r574 23 23 will label the axes with standard LaTeX math formatting. Note that the leading 24 24 space is required, while the trailing space aligns the text with the axis 25 instead of the plot frame. The option 'filter' is used to select datapoints 26 from a given dataset, and takes a quoted list. 25 instead of the plot frame. The option "filter" is used to select datapoints 26 from a given dataset, and takes a quoted list. A "mask" can be given as an 27 integer or a tuple of integers; when the mask is a tuple, the plot will be 2D. 28 The option "vertical" will plot the dataset values on the vertical axis; for 29 2D plots, cones are always plotted on the vertical axis. 27 30 28 31 Required Inputs: … … 33 36 """ 34 37 ZERO = 1.0e-6 # zero-ish 35 _2D = False # use 2d plots36 38 37 39 #### building the cone primitive #### … … 102 104 def plot_bowtie(ax, data, slope, bounds, color='0.75', axis=None): 103 105 if axis not in range(len(bounds)-1): return ax 104 from numpy import asarray 106 from numpy import asarray, inf 105 107 data = asarray(data) 106 ylo = slope[axis] * (bounds[0][0] - data.T[0]) + data.T[1] 107 yhi = slope[axis] * (bounds[0][1] - data.T[0]) + data.T[1] 108 zhi = -slope[axis] * (bounds[0][0] - data.T[0]) + data.T[1] 109 zlo = -slope[axis] * (bounds[0][1] - data.T[0]) + data.T[1] 108 sl = slope[axis] 109 ylo = sl * (bounds[0][0] - data.T[0]) + data.T[1] 110 yhi = sl * (bounds[0][1] - data.T[0]) + data.T[1] 111 zhi = -sl * (bounds[0][0] - data.T[0]) + data.T[1] 112 zlo = -sl * (bounds[0][1] - data.T[0]) + data.T[1] 110 113 xlb = bounds[0][0] 111 114 xub = bounds[0][1] … … 203 206 return ax 204 207 205 def get_slope(data, replace=None ):208 def get_slope(data, replace=None, mask=None): 206 209 """ replace one slope in a list of slopes with '1.0' 207 210 (i.e. replace a slope from the dataset with the unit slope) … … 211 214 """ 212 215 slope = data.lipschitz 216 if mask in range(len(slope)): 217 slope = swap(slope, mask) 213 218 if replace not in range(len(slope)): # don't replace an axis 214 219 return slope 215 220 return slope[:replace] + [1.0] + slope[replace+1:] 216 221 217 def get_coords(data, replace=None ):222 def get_coords(data, replace=None, mask=None): 218 223 """ replace one coordiate axis in a 3-D data set with 'data values' 219 224 (i.e. replace an 'x' axis with the 'y' values of the data) … … 225 230 coords = data.coords 226 231 values = data.values 232 if mask in range(len(slope)): 233 coords = [swap(pt,mask) for pt in coords] 227 234 if replace not in range(len(slope)): # don't replace an axis 228 235 return coords … … 371 378 scale = 1.0 # color = color**scale 372 379 373 try: # select which axis to plot 'values' on 380 _2D = False # if False, use 3D plots; if True, use 3D plots 381 cs = None 382 try: # select which axis to plot 'values' on (3D plot) 374 383 xs = int(parsed_opts.replace) 375 384 except: 376 xs = None # don't plot values; plot values on 'x' axis with xs = 0 385 try: # select which axes to mask (2D plot) 386 xs = eval(parsed_opts.replace) # format is "(1,2)" 387 xs = list(reversed(sorted(set(xs)))) 388 cs = int(xs[-1]) if xs[-1] != xs[0] else None 389 xs = int(xs[0]) 390 xs,cs = cs,xs # cs will swap coord axes; xs will swap with value axis 391 _2D = True #NOTE: always apply cs swap before xs swap 392 except: 393 xs = None # don't plot values; plot values on 'x' axis with xs = 0 377 394 378 395 try: # always plot cones on vertical axis … … 380 397 except: 381 398 vertical_cones = False 399 if _2D: # always plot cones on vertical axis 400 vertical_cones = True 382 401 383 402 # ensure all terms of bounds are tuples … … 407 426 # get dataset coords (and values) for selected axes 408 427 if data: 409 slope = get_slope(data, xs )410 coords = get_coords(data, xs )428 slope = get_slope(data, xs, cs) 429 coords = get_coords(data, xs, cs) 411 430 #print "bounds: %s" % bounds 412 431 #print "slope: %s" % slope … … 433 452 if bounds[i][1] is None: bounds[i][1] = 1 434 453 435 # swap the axes appropriately when plotting cones 436 if vertical_cones and xs in range(len(bounds)): # we are replacing an axis 454 # swap the axes appropriately when plotting cones (when replacing an axis) 455 if _2D and xs == 0: 456 if data: 457 slope[0],slope[1] = slope[1],slope[0] 458 coords = [list(reversed(pt[:2]))+pt[2:] for pt in coords] 459 #bounds[0],bounds[1] = bounds[1],bounds[0] 460 #label[0],label[1] = label[1],label[0] 461 axis = xs #None 462 elif not _2D and vertical_cones and xs in range(len(bounds)): 437 463 # adjust slope, bounds, and data so cone axis is last 438 464 if data: … … 529 555 t = str((s/qp)**scale) 530 556 # get and plot dataset coords for selected axes 531 _coords = get_coords(d, xs) 532 if vertical_cones and xs in range(len(bounds)): # we are replacing an axis 557 _coords = get_coords(d, xs, cs) 558 # check if we are replacing an axis 559 if _2D and xs == 0: 560 if data: # adjust data so cone axis is last 561 _coords = [list(reversed(pt[:2]))+pt[2:] for pt in _coords] 562 elif not _2D and vertical_cones and xs in range(len(bounds)): 533 563 if data: # adjust data so cone axis is last 534 564 _coords = [swap(pt,xs) for pt in _coords]
Note: See TracChangeset
for help on using the changeset viewer.