Changeset 6ed101a in sasview
- Timestamp:
- Apr 29, 2008 5:40:18 PM (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:
- 47f695c9
- Parents:
- f193585
- Location:
- guitools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
rf193585 r6ed101a 67 67 # keep track if the previous transformation of x and y in Property dialog 68 68 self.prevXtrans =" " 69 70 69 self.prevYtrans =" " 71 70 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) 104 105 def onWheel(self, event): 106 """ 107 Process mouse wheel as zoom events 108 """ 109 ax = event.inaxes 110 step = event.step 111 112 if ax != None: 113 # Event occurred inside a plotting area 114 lo,hi = ax.get_xlim() 115 lo,hi = _rescale(lo,hi,step,pt=event.xdata) 116 ax.set_xlim((lo,hi)) 117 118 lo,hi = ax.get_ylim() 119 lo,hi = _rescale(lo,hi,step,pt=event.ydata) 120 ax.set_ylim((lo,hi)) 121 else: 122 # Check if zoom happens in the axes 123 xdata,ydata = None,None 124 x,y = event.x,event.y 125 for ax in self.axes: 126 insidex,_ = ax.xaxis.contains(event) 127 if insidex: 128 xdata,_ = ax.transAxes.inverse_xy_tup((x,y)) 129 #print "xaxis",x,"->",xdata 130 insidey,_ = ax.yaxis.contains(event) 131 if insidey: 132 _,ydata = ax.transAxes.inverse_xy_tup((x,y)) 133 #print "yaxis",y,"->",ydata 134 if xdata is not None: 135 lo,hi = ax.get_xlim() 136 lo,hi = _rescale(lo,hi,step,bal=xdata) 137 ax.set_xlim((lo,hi)) 138 if ydata is not None: 139 lo,hi = ax.get_ylim() 140 lo,hi = _rescale(lo,hi,step,bal=ydata) 141 ax.set_ylim((lo,hi)) 142 143 self.canvas.draw_idle() 144 145 72 146 def returnTrans(self): 73 147 return self.xscales,self.yscales … … 265 339 self.subplot.clear() 266 340 self.subplot.hold(True) 267 341 268 342 def render(self): 269 343 """Commit the plot after all objects are drawn""" -
guitools/canvas.py
rf193585 r6ed101a 53 53 """Translate mouse wheel events into matplotlib events""" 54 54 # Determine mouse location 55 w,h = self.figure.canvas.get_width_height() 55 56 x = evt.GetX() 56 y = self.figure.bbox.height- evt.GetY()57 y = h - evt.GetY() 57 58 58 59 # Convert delta/rotation/rate into a floating point step size -
guitools/plottables.py
rf193585 r6ed101a 406 406 return 1 407 407 408 def transform_x(self, func, errfunc): 409 """ 410 @param func: reference to x transformation function 411 412 """ 413 self.view.transform_x(func, errfunc, x=self.x, y=self.y, dx=self.dx, dy=self.dy) 414 415 def transform_y(self, func, errfunc): 416 """ 417 @param func: reference to y transformation function 418 419 """ 420 self.view.transform_y(func, errfunc, self.y, self.x, self.dx, self.dy) 421 408 def transformView(self): 409 410 self.view.transform( self.x, self.y, self.dx,self.dy) 422 411 423 412 def returnValuesOfView(self): … … 460 449 self.funcdx= None 461 450 self.funcdy= None 462 463 def transform_x(self, func, errfunc, x,y=None,dx=None, dy=None): 451 def transform(self, x=None,y=None,dx=None, dy=None): 464 452 """ 465 453 Transforms the x and dx vectors and stores the output. … … 473 461 474 462 # Sanity check 475 has_y = False 476 if dx and not len(x)==len(dx): 477 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 478 # Check length of y array 479 if not y==None: 463 if (x!=None) and (y!=None): 464 if dx and not len(x)==len(dx): 465 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 466 # Check length of y array 480 467 if not len(y)==len(x): 481 468 raise ValueError, "Plottable.View: Given y and x are not of the same length" 482 else: 483 has_y = True 469 484 470 if dy and not len(y)==len(dy): 485 471 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 486 487 self.x = [] 488 self.dx = [] 489 tempy=[] 490 tempdy=[] 491 print "this is initial value of y transformed",self.y 492 print "this is initial value of dy transformed",self.dy 493 for i in range(len(x)): 494 if has_y: 495 try: 496 xtemp = func(x[i],y[i]) 497 tempy.append(self.funcy.y[i]) 498 tempdy.append(self.funcdy.dy[i]) 499 if (dx!=None) and (dy !=None): 500 dxtemp = errfunc(x[i], y[i], dx[i], dy[i]) 501 elif (dx != None): 502 dxtemp = errfunc(x[i], y[i], dx[i],0) 503 elif (dy != None): 504 dxtemp = errfunc(x[i], y[i],0,dy[i]) 505 else: 506 dxtemp = errfunc(x[i],y[i],0, 0) 507 self.x.append(xtemp) 508 self.dx.append(dxtemp) 509 except: 510 if len(tempy)>0: 511 del tempy[len(tempy)-1] 512 del tempdy[len(tempdy)-1] 472 self.x = [] 473 self.y = [] 474 self.dx = [] 475 self.dy = [] 476 tempx=[] 477 tempdx=[] 478 tempy=[] 479 tempdy=[] 480 if dx==None: 481 dx=numpy.zeros(len(x)) 482 if dy==None: 483 dy=numpy.zeros(len(y)) 484 485 for i in range(len(x)): 486 try: 487 tempx =self.funcx(x[i],y[i]) 488 tempy =self.funcy(y[i],x[i]) 489 tempdx = self.funcdx(x[i], y[i], dx[i], dy[i]) 490 tempdy = self.funcdy(y[i], x[i], dy[i], dx[i]) 491 492 self.x.append(tempx) 493 self.y.append(tempy) 494 self.dx.append(tempdx) 495 self.dy.append(tempdy) 496 except: 497 513 498 print "View.transform_x: skipping point %g" % x[i] 514 499 print sys.exc_value 515 else: 516 try: 517 xtemp = func(x[i]) 518 tempy.append(self.funcy.y[i]) 519 tempdy.append(self.funcdy.dy[i]) 520 if (dx != None): 521 dxtemp = errfunc(x[i], dx[i]) 522 else: 523 dxtemp = errfunc(x[i],None) 524 self.x.append(xtemp) 525 self.dx.append(dxtemp) 526 except: 527 if len(tempy)>0: 528 del tempy[len(tempy)-1] 529 del tempdy[len(tempdy)-1] 530 print "View.transform_x: skipping point %g" % x[i] 531 print sys.exc_value 532 self.y=tempy 533 self.dy=tempdy 534 self.Xreel = [] 535 self.DXreel=[] 500 # Sanity check 501 if not (len(self.x)==len(self.dx))and(len(self.x)==len(self.dy))\ 502 and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 503 raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length" 504 536 505 def returntransformx(self,funcx,funcdx): 537 506 self.funcx= funcx … … 541 510 self.funcy= funcy 542 511 self.funcdy= funcdy 543 def transform_y(self, func, errfunc, y, x=None,dx=None,dy=None): 544 """ 545 Transforms the y and dy vectors and stores the output. 546 547 @param func: function to apply to the data y 548 @param x: array of x values 549 @param dx: array of error values 550 @param y: array of y values 551 @param dy: array of error values 552 @param errfunc: function to apply to errors dy 553 """ 554 # Sanity check 555 has_x = False 556 if dy and not len(y)==len(dy): 557 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 558 # Check length of x array 559 if not x==None: 560 if not len(y)==len(x): 561 raise ValueError, "Plottable.View: Given y and x are not of the same length" 562 else: 563 has_x = True 564 if dx and not len(x)==len(dx): 565 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 566 567 self.y = [] 568 self.dy = [] 569 tempx=[] 570 tempdx=[] 571 print "this is initial value of x transformed",self.x 572 print "this is initial value of dx transformed",self.dx 573 for i in range(len(y)): 574 575 if has_x: 576 try: 577 tempy = func(y[i],x[i]) 578 tempx.append(self.funcx.x[i]) 579 tempdx.append(self.funcdx.x[i]) 580 if (dx!=None) and (dy !=None): 581 tempdy = errfunc(y[i], x[i], dy[i], dx[i]) 582 elif (dx != None): 583 tempdy = errfunc(y[i], x[i], 0, dx[i]) 584 elif (dy != None): 585 tempdy = errfunc(y[i], x[i], dy[i], 0) 586 else: 587 tempdy = errfunc(y[i], None) 588 self.y.append(tempy) 589 self.dy.append(tempdy) 590 except: 591 if len(tempx)>0: 592 del tempx[len(tempx)-1] 593 del tempdx[len(tempdx)-1] 594 print "View.transform_y: skipping point %g" % y[i] 595 print sys.exc_value 596 597 else: 598 try: 599 tempy = func(y[i]) 600 tempx.append(self.funcx.x[i]) 601 tempdx.append(self.funcdx.dx[i]) 602 if (dy != None): 603 tempdy = errfunc( y[i],dy[i]) 604 else: 605 tempdy = errfunc( y[i],None) 606 self.y.append(tempy) 607 self.dy.append(tempdy) 608 except: 609 if len(tempx)>0: 610 del tempx[len(tempx)-1] 611 del tempdx[len(tempdx)-1] 612 print "View.transform_y: skipping point %g" % y[i] 613 print sys.exc_value 614 615 self.x = tempx 616 self.dx = tempdx 617 self.Yreel = [] 618 self.DYreel=[] 619 self.Yreel = self.y 620 self.DYreel = self.dy 621 print "this is x length",self.x 622 print "this is y length",self.y 623 print "this is dx length",self.dx 624 print "this is dy length",self.dy 512 625 513 def returnXview(self): 626 514 return self.x,self.y,self.dx,self.dy … … 638 526 tempy=[] 639 527 tempdy=[] 528 if self.dx==None: 529 self.dx=numpy.zeros(len(self.x)) 530 if self.dy==None: 531 self.dy=numpy.zeros(len(self.y)) 640 532 if self.transx=="log10(x)" : 641 533 for i in range(len(self.x)): … … 651 543 print sys.exc_value 652 544 pass 653 if (self.transx == "x"): 654 if (self.transy == "ln(y*x)"): 655 try: 656 if (self.y[i]*self.x[i]> 0): 657 tempx.append(self.x[i]) 658 tempdx.append(self.dx[i]) 659 tempy.append(self.y[i]) 660 tempdy.append(self.dy[i]) 661 except: 662 #print "View.transform_x: skipping point %g" %self.x[i] 663 print sys.exc_value 664 pass 665 if(self.transy =="ln(y*x^(2))")or(self.transy =="ln(y*x^(4))"): 666 print "this is y transform",self.y 667 print "this is x transform",self.x 668 try: 669 if (self.y[i]> 0 )and (self.x[i]!=0): 670 tempx.append(self.x[i]) 671 tempdx.append(self.dx[i]) 672 tempy.append(self.y[i]) 673 tempdy.append(self.dy[i]) 674 except: 675 #print "View.transform_x: skipping point %g" %self.x[i] 676 print sys.exc_value 677 pass 545 678 546 self.x=[] 679 547 self.dx=[] … … 690 558 tempy=[] 691 559 tempdy=[] 692 for i in range(len(self.x)): 693 if (self.transy == "ln(y)") or (self.transy == "log10(y)" )or\ 694 (self.transy =="1/sqrt(y)") : 560 if self.dx==None: 561 self.dx=numpy.zeros(len(self.x)) 562 if self.dy==None: 563 self.dy=numpy.zeros(len(self.y)) 564 if (self.transy == "log10(y)" ): 565 for i in range(len(self.x)): 695 566 try: 696 567 if (self.y[i]> 0): … … 703 574 print sys.exc_value 704 575 pass 705 if(self.transy == "1/y"):706 try:707 if (self.y[i]!=0):708 tempx.append(self.x[i])709 tempdx.append(self.dx[i])710 tempy.append(self.y[i])711 tempdy.append(self.dy[i])712 except:713 #print "View.transform_x: skipping point %g" %self.x[i]714 print sys.exc_value715 pass716 if (self.transx == "x"):717 if (self.transy == "ln(y*x)"):718 try:719 if (self.y[i]*self.x[i]> 0):720 tempx.append(self.x[i])721 tempdx.append(self.dx[i])722 tempy.append(self.y[i])723 tempdy.append(self.dy[i])724 except:725 #print "View.transform_x: skipping point %g" %self.x[i]726 print sys.exc_value727 pass728 if(self.transy =="ln(y*x^(2))")or(self.transy =="ln(y*x^(4))"):729 print "this is y transform",self.y730 print "this is x transform",self.x731 try:732 if (self.y[i]> 0 )and (self.x[i]!= 0):733 tempx.append(self.x[i])734 tempdx.append(self.dx[i])735 tempy.append(self.y[i])736 tempdy.append(self.dy[i])737 except:738 #print "View.transform_x: skipping point %g" %self.x[i]739 print sys.exc_value740 pass741 576 742 577 self.x=[]
Note: See TracChangeset
for help on using the changeset viewer.