- Timestamp:
- Apr 30, 2008 10:52:41 AM (17 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
- Location:
- guitools
- Files:
-
- 2 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 -
guitools/plottables.py
r6ed101a r47f695c9 383 383 """ Reload view with new value to plot""" 384 384 self.view = self.View(self.x, self.y, self.dx, self.dy) 385 #save the initial value 386 self.view.Xreel = self.view.x 387 self.view.Yreel = self.view.y 388 self.view.DXreel = self.view.dx 389 self.view.DYreel = self.view.dy 390 391 385 392 386 def render(self,plot): 393 387 """The base class makes sure the correct units are being used for … … 438 432 self.dx = dx 439 433 self.dy = dy 440 #to change x range to the reel range 441 self.Xreel = self.x 442 self.Yreel = self.y 443 self.DXreel = self.dx 444 self.DYreel = self.dy 434 445 435 self.transx ="" 446 436 self.transy ="" … … 459 449 """ 460 450 461 462 451 # Sanity check 463 452 if (x!=None) and (y!=None): … … 474 463 self.dx = [] 475 464 self.dy = [] 476 tempx=[] 477 tempdx=[] 478 tempy=[] 479 tempdy=[] 465 480 466 if dx==None: 481 467 dx=numpy.zeros(len(x)) 482 468 if dy==None: 483 469 dy=numpy.zeros(len(y)) 484 470 485 471 for i in range(len(x)): 486 472 try: … … 495 481 self.dy.append(tempdy) 496 482 except: 497 498 print "View.transform_x: skipping point %g" % x[i] 499 print sys.exc_value 483 print "View.transform: skipping point x %g" % x[i] 484 print "View.transform: skipping point y %g" % y[i] 485 print "View.transform: skipping point dy %g" % dy[i] 486 print sys.exc_value 487 print len(self.x) 488 print len(self.dx) 489 print len(self.y) 490 print len(self.dy) 500 491 # Sanity check 501 492 if not (len(self.x)==len(self.dx))and(len(self.x)==len(self.dy))\ 502 493 and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 503 494 raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length" 504 495 self.check_data_logX() 496 self.check_data_logY() 497 print len(self.x) 498 print len(self.dx) 499 print len(self.y) 500 print len(self.dy) 505 501 def returntransformx(self,funcx,funcdx): 506 502 self.funcx= funcx … … 515 511 516 512 517 def reelXrange(self):518 self.x= self.Xreel519 self.y= self.Yreel520 self.dx= self.DXreel521 self.dy= self.DYreel522 523 513 def check_data_logX(self): 524 514 tempx=[] … … 540 530 tempdy.append(self.dy[i]) 541 531 except: 542 #print "View.transform_x: skipping point%g" %self.x[i]532 print "check_data_logX: skipping point x %g" %self.x[i] 543 533 print sys.exc_value 544 534 pass 545 535 546 self.x=[]547 self.dx=[]548 self.y=[]549 self.dy=[]550 self.x=tempx551 self.y=tempy552 self.dx=tempdx553 self.dy=tempdy536 self.x=[] 537 self.dx=[] 538 self.y=[] 539 self.dy=[] 540 self.x=tempx 541 self.y=tempy 542 self.dx=tempdx 543 self.dy=tempdy 554 544 555 545 def check_data_logY(self): … … 571 561 tempdy.append(self.dy[i]) 572 562 except: 573 #print "View.transform_x: skipping point %g" %self.x[i]563 print "check_data_logY: skipping point %g" %self.y[i] 574 564 print sys.exc_value 575 565 pass 576 566 577 self.x=[]578 self.dx=[]579 self.y=[]580 self.dy=[]581 self.x=tempx582 self.y=tempy583 self.dx=tempdx584 self.dy=tempdy567 self.x=[] 568 self.dx=[] 569 self.y=[] 570 self.dy=[] 571 self.x=tempx 572 self.y=tempy 573 self.dx=tempdx 574 self.dy=tempdy 585 575 586 576
Note: See TracChangeset
for help on using the changeset viewer.