Changeset 47f695c9 in sasview for guitools/PlotPanel.py
- Timestamp:
- Apr 30, 2008 10:52:41 AM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- eca05c8
- Parents:
- 6ed101a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r6ed101a r47f695c9 23 23 if 'get_children' in dir(obj): 24 24 for a in obj.get_children(): show_tree(a,d+1) 25 25 def _rescale(lo,hi,step,pt=None,bal=None,scale='linear'): 26 """ 27 Rescale (lo,hi) by step, returning the new (lo,hi) 28 The scaling is centered on pt, with positive values of step 29 driving lo/hi away from pt and negative values pulling them in. 30 If bal is given instead of point, it is already in [0,1] coordinates. 31 32 This is a helper function for step-based zooming. 33 """ 34 # Convert values into the correct scale for a linear transformation 35 # TODO: use proper scale transformers 36 if scale=='log': 37 lo,hi = log10(lo),log10(hi) 38 if pt is not None: pt = log10(pt) 39 40 # Compute delta from axis range * %, or 1-% if persent is negative 41 if step > 0: 42 delta = float(hi-lo)*step/100 43 else: 44 delta = float(hi-lo)*step/(100-step) 45 46 # Add scale factor proportionally to the lo and hi values, preserving the 47 # point under the mouse 48 if bal is None: 49 bal = float(pt-lo)/(hi-lo) 50 lo = lo - bal*delta 51 hi = hi + (1-bal)*delta 52 53 # Convert transformed values back to the original scale 54 if scale=='log': 55 lo,hi = pow(10.,lo),pow(10.,hi) 56 57 return (lo,hi) 26 58 27 59 … … 69 101 self.prevYtrans =" " 70 102 self.canvas.mpl_connect('scroll_event',self.onWheel) 71 def _rescale(lo,hi,step,pt=None,bal=None,scale='linear'): 72 """ 73 Rescale (lo,hi) by step, returning the new (lo,hi) 74 The scaling is centered on pt, with positive values of step 75 driving lo/hi away from pt and negative values pulling them in. 76 If bal is given instead of point, it is already in [0,1] coordinates. 77 78 This is a helper function for step-based zooming. 79 """ 80 # Convert values into the correct scale for a linear transformation 81 # TODO: use proper scale transformers 82 if scale=='log': 83 lo,hi = log10(lo),log10(hi) 84 if pt is not None: pt = log10(pt) 85 86 # Compute delta from axis range * %, or 1-% if persent is negative 87 if step > 0: 88 delta = float(hi-lo)*step/100 89 else: 90 delta = float(hi-lo)*step/(100-step) 91 92 # Add scale factor proportionally to the lo and hi values, preserving the 93 # point under the mouse 94 if bal is None: 95 bal = float(pt-lo)/(hi-lo) 96 lo = lo - bal*delta 97 hi = hi + (1-bal)*delta 98 99 # Convert transformed values back to the original scale 100 if scale=='log': 101 lo,hi = pow(10.,lo),pow(10.,hi) 102 103 return (lo,hi) 103 self.axes = [self.subplot] 104 104 105 105 def onWheel(self, event): … … 120 120 ax.set_ylim((lo,hi)) 121 121 else: 122 # Check if zoom happens in the axes122 # Check if zoom happens in the axes 123 123 xdata,ydata = None,None 124 124 x,y = event.x,event.y … … 249 249 250 250 251 252 def onselect(self,event1, event2): 253 print"went here" 254 from matplotlib.widgets import RectangleSelector 255 from pylab import show, gca, gcf 256 257 'event1 and event2 are the press and release events' 258 x1, y1 = event1.xdata, event1.ydata 259 x2, y2 = event2.xdata, event2.ydata 260 print "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2) 261 print " The button you used were: ",event1.button, event2.button 262 gca().set_xlim([x1,x2]) 263 gca().set_ylim([y1,y2]) 264 gcf().canvas.draw_idle() 265 266 # drawtype is 'box' or 'line' or 'none' 267 LS = RectangleSelector(self.subplot, onselect,drawtype='box',useblit=True) 268 show() 269 270 271 251 272 252 273 253 def onSaveImage(self, evt): … … 432 412 if ( self.xscales=="x" ): 433 413 item.returnTransformationx(transform.toX,transform.errToX) 434 435 414 self.set_xscale("linear") 436 415 name, units = item.get_xaxis() … … 453 432 self.set_yscale("linear") 454 433 name, units = item.get_yaxis() 455 item.check_data_PlottableY()456 434 self.graph.yaxis("log %s" % name, "%s^{-1}" % units) 457 435 … … 464 442 if ( self.yscales=="log10(y)" ): 465 443 item.returnTransformationy(transform.toX,transform.errToX) 466 item.check_data_PlottableY()467 444 self.set_yscale("log") 468 445 name, units = item.get_yaxis() … … 485 462 self.set_yscale("linear") 486 463 name, units = item.get_yaxis() 487 item.check_data_PlottableY()488 464 self.graph.yaxis("%s" %name, "%s" % units) 489 465 … … 499 475 self.set_yscale("linear") 500 476 yname, yunits = item.get_yaxis() 501 xname, xunits = item.get_xaxis() 502 item.check_data_PlottableY() 477 xname, xunits = item.get_xaxis() 503 478 self.graph.yaxis("Log %s%s^{2}" % (yname,xname), "%s^{-1}%s^{-2}" % (yunits,xunits)) 504 479
Note: See TracChangeset
for help on using the changeset viewer.