- Timestamp:
- 09/20/12 14:55:38 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UQ/math/legacy/plot_data.py
r564 r565 97 97 98 98 #### plotting the cones #### 99 def plot_cones(ax, data, slope, bounds, color='0.75', axis= -1):99 def plot_cones(ax, data, slope, bounds, color='0.75', axis=None): 100 100 """plot double cones for a given dataset 101 101 … … 116 116 _cone = cone(datapt, top=True) 117 117 if _cone: 118 X,Z,Y = swap(_cone, xs) # 'unswap' the axes119 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) 120 120 _cone = cone(datapt, top=False) 121 121 if _cone: 122 X,Z,Y = swap(_cone, xs) # 'unswap' the axes123 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) 124 124 return ax 125 125 126 def plot_data(ax, data, bounds, color='red' , axis=-1):126 def plot_data(ax, data, bounds, color='red'): 127 127 """plot datapoints for a given dataset 128 128 … … 131 131 bounds -- list of tuples of bounds for the plot; (lower,upper) for each axis 132 132 color -- string name (or rbg value) of color to use for datapoints 133 axis -- the axis of the cone134 133 """ 135 134 strict = True # always respect the bounds … … 144 143 pass # don't plot if datapt is out of bounds 145 144 else: 146 ax.plot([datapt[0]], [datapt[ 2]], [datapt[1]], \145 ax.plot([datapt[0]], [datapt[1]], [datapt[2]], \ 147 146 color=color, marker='o', markersize=10) 148 147 return ax … … 157 156 # plot only within [lb,ub] 158 157 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" axis158 ax.set_ylim3d(lb[1], ub[1]) 159 ax.set_zlim3d(lb[2], ub[2]) # cone "center" axis 161 160 return ax 162 161 … … 168 167 """ 169 168 ax.set_xlabel(labels[0]) 170 ax.set_ zlabel(labels[1])171 ax.set_ ylabel(labels[2]) # cone "center" axis169 ax.set_ylabel(labels[1]) 170 ax.set_zlabel(labels[2]) # cone "center" axis 172 171 return ax 173 172 … … 189 188 return coords, slope 190 189 191 def reduce(alist, axis=-1):192 """ reduce a n-member list to a (n-1)-memberlist193 194 alist -- a list 195 axis -- selected member (an int) to remove190 def 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 196 195 """ 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 203 197 return alist 204 return alist[: axis] + alist[axis+1:] + alist[axis:axis+1]198 return alist[:index] + alist[index+1:] + alist[index:index+1] 205 199 206 200 … … 223 217 metavar="INT",default=None, 224 218 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") 225 221 parsed_opts, parsed_args = parser.parse_args() 226 222 … … 262 258 xs = None # don't plot values; plot values on 'x' axis with xs = 0 263 259 260 try: # always plot cones on vertical axis 261 vertical_cones = parsed_opts.vertical 262 except: 263 vertical_cones = False 264 264 265 # ensure all terms of bounds and xyz are tuples 265 266 for bound in bounds: … … 273 274 274 275 # get coords (and values) for selected axes 275 coords, slope = get_coords(data, xs) #FIXME: requires Y-value to be last276 coords, slope = get_coords(data, xs) 276 277 print "bounds: %s" % bounds 277 278 print "slope: %s" % slope … … 290 291 ax = Axes3D(fig)#,aspect='equal') 291 292 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 292 300 plot_cones(ax, coords, slope, bounds, axis=xs) 293 plot_data(ax, coords, bounds , axis=xs)301 plot_data(ax, coords, bounds) 294 302 #clip_axes(ax, bounds) 295 303 label_axes(ax, label)
Note: See TracChangeset
for help on using the changeset viewer.