- Timestamp:
- 09/18/12 14:07:03 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UQ/math/legacy/plot_data.py
r546 r562 3 3 4 4 #### building the cone primitive #### 5 def cone_builder(slope, lb, ub):5 def cone_builder(slope, bounds): 6 6 """ factory to create a cone primitive 7 7 8 8 slope -- slope multiplier for cone on the X,Y,Z axes (for mesh construction) 9 lb -- tuple of lower bounds for the plot view 10 ub -- tuple of upper bounds for the plot view 9 bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 11 10 """ 12 11 from mystic.math import almostEqual … … 35 34 return X,Z,Y 36 35 36 lb,ub = zip(*bounds) 37 # if False, the cone surface may violate bounds 38 strict = True # always respect the bounds 39 37 40 def cone(position, top=True): 38 41 """ construct a cone primitive, with vertex at given position … … 45 48 d_hi = ub - position 46 49 d_lo = lb - position 47 # check if out of bounds 48 if any(d_hi < 0): return None #FIXME: poor design 49 if any(d_lo > 0): return None #FIXME: poor design 50 if strict and (any(d_hi < 0) or any(d_lo > 0)): 51 return None # don't plot cone if vertex is out of bounds 50 52 51 53 if top: # distance of vertex from upper edge … … 65 67 66 68 #### plotting the cones #### 67 def plot_cones(ax, data, slope, lb, ub):69 def plot_cones(ax, data, slope, bounds): 68 70 """plot double cones for a given dataset 69 71 … … 71 73 data -- list of datapoints, where datapoints are 3-tuples (i.e. x,y,z) 72 74 slope -- slope multiplier for cone on the X,Y,Z axes (for mesh construction) 73 lb -- tuple of lower bounds for the plot view 74 ub -- tuple of upper bounds for the plot view 75 bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 75 76 """ 76 cone = cone_builder(slope, lb, ub)77 cone = cone_builder(slope, bounds) 77 78 # plot the upper and lower cone 78 79 for datapt in data: … … 87 88 return ax 88 89 89 def plot_data(ax, data ):90 def plot_data(ax, data, bounds): 90 91 """plot datapoints for a given dataset 91 92 92 93 ax -- matplotlib 'Axes3D' plot object 93 94 data -- list of datapoints, where datapoints are 3-tuples (i.e. x,y,z) 95 bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 94 96 """ 97 strict = True # always respect the bounds 98 lb,ub = zip(*bounds) 95 99 # plot the datapoints themselves 100 from numpy import asarray 96 101 for datapt in data: 97 ax.plot([datapt[0]], [datapt[2]], [datapt[1]], \ 98 color='r', marker='o', markersize=10) 102 position = asarray(datapt) 103 d_hi = ub - position 104 d_lo = lb - position 105 if strict and (any(d_hi < 0) or any(d_lo > 0)): 106 pass # don't plot if datapt is out of bounds 107 else: 108 ax.plot([datapt[0]], [datapt[2]], [datapt[1]], \ 109 color='r', marker='o', markersize=10) 99 110 return ax 100 111 101 def clip_axes(ax, lb, ub):112 def clip_axes(ax, bounds): 102 113 """ clip plots to be within given lower and upper bounds 103 114 104 115 ax -- matplotlib 'Axes3D' plot object 105 lb -- tuple of lower bounds for the plot view 106 ub -- tuple of upper bounds for the plot view 116 bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 107 117 """ 118 lb,ub = zip(*bounds) 108 119 # plot only within [lb,ub] 109 120 ax.set_xlim3d(lb[0], ub[0]) … … 112 123 return ax 113 124 114 def reduce_dimension(axis, coords, values, slope, lb, ub):125 def reduce_dimension(axis, coords, values, slope, bounds): 115 126 """ replace one coordiate axis in a 3-D data set with 'data values' 116 127 (i.e. replace an 'x' axis with the 'y' values of the data) … … 120 131 values -- list of datapoint values, where values are floats 121 132 slope -- slope multiplier for cone on the X,Y,Z axes 122 lb -- tuple of lower bounds for the plot view 123 ub -- tuple of upper bounds for the plot view 133 bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 124 134 125 135 NOTE: for the axis indicated by 'axis', replace … … 128 138 - selected slope with 1.0 129 139 """ 140 if axis not in range(len(bounds[:-1])): # don't replace an axis 141 return coords, slope[:-1], bounds[:-1] 130 142 xs = axis 131 lb = lb[:xs] + lb[xs+1:] 132 ub = ub[:xs] + ub[xs+1:] 143 bounds = bounds[:xs] + bounds[xs+1:] 133 144 slope = slope[:xs] + slope[xs+1:] 134 145 coords = [coords[i][:xs] + coords[i][xs+1:] + [values[i]] \ 135 146 for i in range(len(coords))] 136 return coords, slope, lb, ub147 return coords, slope, bounds 137 148 138 149 … … 149 160 h_lower = [0.062]; a_lower = [0.0]; v_lower = [2300.0] 150 161 h_upper = [0.125]; a_upper = [30.0]; v_upper = [3200.0] 151 axis_to_replace = xs = 0 #XXX: select axis NOT to plot here162 axis_to_replace = xs = 0 #XXX: select axis NOT to plot here 152 163 164 # temporarily 'inflate' bounds and slopes to include values 153 165 lb = h_lower + a_lower + v_lower + Y_lower 154 166 ub = h_upper + a_upper + v_upper + Y_upper 155 167 bounds = zip(lb,ub) 156 168 slope = data.lipschitz + [1.0] 157 169 coords = data.coords 158 170 values = data.values 171 # replace selected coords axis; 'reduce' the size of bounds and slopes 172 coords, slope, bounds = reduce_dimension(xs, coords, values, slope, bounds) 159 173 160 coords, slope, lb, ub = reduce_dimension(xs, coords, values, slope, lb, ub) 161 162 print "lower: %s" % lb 163 print "upper: %s" % ub 174 print "bounds: %s" % bounds 164 175 print "slope: %s" % slope 165 176 #print "coords: %s" % coords … … 170 181 fig = plt.figure() 171 182 ax = Axes3D(fig)#,aspect='equal') 172 plot_cones(ax, coords, slope, lb, ub) 173 plot_data(ax, coords) 174 #clip_axes(ax, lb, ub) 183 if xs in range(len(bounds)): # we are replacing an axis 184 plot_cones(ax, coords, slope, bounds) 185 plot_data(ax, coords, bounds) 186 clip_axes(ax, bounds) 175 187 plt.show() 176 188
Note: See TracChangeset
for help on using the changeset viewer.