Changeset b43a009 in sasview for guitools/plottables.py
- Timestamp:
- May 5, 2008 2:44:40 PM (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:
- edce46e
- Parents:
- 2d06beb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/plottables.py
r150c04a rb43a009 53 53 if not cond: return False 54 54 return True 55 def error_msg(msg, parent=None): 56 """ 57 Signal an error condition -- in a GUI, popup a error dialog 58 """ 59 # Code brought with minor podifications from mpl.backends.backend_wx 60 # Copyright (C) Jeremy O'Donoghue & John Hunter, 2003-4 61 dialog =wx.MessageDialog(parent = parent, 62 message = msg, 63 caption = 'Polplot error', 64 style=wx.OK | wx.CENTRE) 65 dialog.ShowModal() 66 dialog.Destroy() 67 return None 55 68 56 # Graph structure for holding multiple plottables 69 57 class Graph: … … 204 192 "title":""} 205 193 self.plottables = {} 206 def setGraph(self,listofplottable):207 self.plottables = listofplottable194 195 208 196 def _make_labels(self): 209 197 # Find groups of related plottables … … 223 211 224 212 def returnPlottable(self): 213 """ 214 This method returns a dictionary of plottables contained in graph 215 It is just by Plotpanel to interact with the complete list of plottables 216 inside the graph. 217 """ 225 218 return self.plottables 226 219 … … 234 227 plot.render() 235 228 236 def clear(self,plot): 237 plot.clear() 229 238 230 239 231 def __init__(self,**kw): … … 376 368 ##Use the following if @classmethod doesn't work 377 369 # labels = classmethod(labels) 378 def getTransform(self,transx,transy): 379 self.view.transx = transx 380 self.view.transy = transy 370 def setLabel(self,labelx,labely): 371 """ 372 It takes a label of the x and y transformation and set View parameters 373 @param transx: The label of x transformation is sent by Properties Dialog 374 @param transy: The label of y transformation is sent Properties Dialog 375 """ 376 self.view.xLabel= labelx 377 self.view.yLabel = labely 381 378 382 379 def __init__(self): … … 418 415 419 416 def transformView(self): 420 417 """ 418 It transforms x, y before displaying 419 """ 421 420 self.view.transform( self.x, self.y, self.dx,self.dy) 422 421 423 422 def returnValuesOfView(self): 423 """ 424 Return View parameters and it is used by Fit Dialog 425 """ 424 426 return self.view.returnXview() 425 427 426 428 def check_data_PlottableX(self): 429 """ 430 Since no transformation is made for log10(x), check that 431 no negative values is plot in log scale 432 """ 427 433 self.view.check_data_logX() 428 434 429 435 def check_data_PlottableY(self): 436 """ 437 Since no transformation is made for log10(y), check that 438 no negative values is plot in log scale 439 """ 430 440 self.view.check_data_logY() 431 441 432 def returnTransformationx(self,transx,transdx): 433 self.view.returntransformx(transx,transdx) 434 435 def returnTransformationy(self,transy,transdy): 436 self.view.returntransformy(transy,transdy) 442 def transformX(self,transx,transdx): 443 """ 444 Receive pointers to function that transform x and dx 445 and set corresponding View pointers 446 @param transx: pointer to function that transforms x 447 @param transdx: pointer to function that transforms dx 448 """ 449 self.view.setTransformX(transx,transdx) 450 451 def transformY(self,transy,transdy): 452 """ 453 Receive pointers to function that transform y and dy 454 and set corresponding View pointers 455 @param transy: pointer to function that transforms y 456 @param transdy: pointer to function that transforms dy 457 """ 458 self.view.setTransformY(transy,transdy) 459 437 460 def onReset(self): 461 """ 462 Reset x, y, dx, dy view with its parameters 463 """ 438 464 self.view.onResetView() 465 439 466 def onFitRange(self,xmin=None,xmax=None): 467 """ 468 It limits View data range to plot from min to max 469 @param xmin: the minimum value of x to plot. 470 @param xmax: the maximum value of x to plot 471 """ 440 472 self.view.onFitRangeView(xmin,xmax) 473 441 474 class View: 442 475 """ … … 454 487 self.dx = dx 455 488 self.dy = dy 456 # to change x range to the reel range489 # To change x range to the reel range 457 490 self.Xreel = self.x 458 491 self.Yreel = self.y 459 492 self.DXreel = self.dx 460 493 self.DYreel = self.dy 461 462 self. transx=""463 self. transy=""464 # function to transform x andy494 # Labels of x and y received from Properties Dialog 495 self.xLabel ="" 496 self.yLabel ="" 497 # Function to transform x, y, dx and dy 465 498 self.funcx= None 466 499 self.funcy= None … … 469 502 def transform(self, x=None,y=None,dx=None, dy=None): 470 503 """ 471 Transforms the x and dx vectors and stores the output. 472 473 @param func: function to apply to the data 504 Transforms the x,y,dx and dy vectors and stores the output in View parameters 505 474 506 @param x: array of x values 475 @param dx: array of error values 476 @param errfunc: function to apply to errors 507 @param y: array of y values 508 @param dx: array of errors values on x 509 @param dy: array of error values on y 477 510 """ 478 511 479 512 # Sanity check 480 if (x!=None) and (y!=None): 513 # Do the transofrmation only when x and y are empty 514 if (x!=None) and (y!=None): 481 515 if dx and not len(x)==len(dx): 482 516 raise ValueError, "Plottable.View: Given x and dx are not of the same length" … … 522 556 and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 523 557 raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length" 558 # Check that negative values are not plot on x and y axis for log10 transformation 524 559 self.check_data_logX() 525 560 self.check_data_logY() 561 # Store x ,y dx,and dy in their full range for reset 526 562 self.Xreel = self.x 527 563 self.Yreel = self.y 528 564 self.DXreel = self.dx 529 565 self.DYreel = self.dy 566 567 568 530 569 def onResetView(self): 531 self.x=self.Xreel 532 self.y=self.Yreel 533 self.dx=self.DXreel 534 self.dy=self.DYreel 535 def returntransformx(self,funcx,funcdx): 570 """ 571 Reset x,y,dx and y in their full range and in the initial scale 572 in case their previous range has changed 573 """ 574 self.x = self.Xreel 575 self.y = self.Yreel 576 self.dx = self.DXreel 577 self.dy = self.DYreel 578 579 def setTransformX(self,funcx,funcdx): 580 """ 581 Receive pointers to function that transform x and dx 582 and set corresponding View pointers 583 @param transx: pointer to function that transforms x 584 @param transdx: pointer to function that transforms dx 585 """ 536 586 self.funcx= funcx 537 587 self.funcdx= funcdx 538 588 539 def returntransformy(self,funcy,funcdy): 589 def setTransformY(self,funcy,funcdy): 590 """ 591 Receive pointers to function that transform y and dy 592 and set corresponding View pointers 593 @param transx: pointer to function that transforms y 594 @param transdx: pointer to function that transforms dy 595 """ 540 596 self.funcy= funcy 541 597 self.funcdy= funcdy 542 598 543 599 def returnXview(self): 600 """ 601 Return View x,y,dx,dy 602 """ 544 603 return self.x,self.y,self.dx,self.dy 545 604 546 605 547 606 def check_data_logX(self): 607 """ 608 Remove negative value in x vector 609 to avoid plotting negative value of Log10 610 """ 548 611 tempx=[] 549 612 tempdx=[] … … 554 617 if self.dy==None: 555 618 self.dy=numpy.zeros(len(self.y)) 556 if self. transx=="log10(x)" :619 if self.xLabel=="log10(x)" : 557 620 for i in range(len(self.x)): 558 621 try: … … 568 631 pass 569 632 570 self.x=[] 571 self.dx=[] 572 self.y=[] 573 self.dy=[] 574 self.x=tempx 575 self.y=tempy 576 self.dx=tempdx 577 self.dy=tempdy 633 self.x = tempx 634 self.y = tempy 635 self.dx = tempdx 636 self.dy = tempdy 578 637 579 638 def check_data_logY(self): 639 """ 640 Remove negative value in y vector 641 to avoid plotting negative value of Log10 642 """ 580 643 tempx=[] 581 644 tempdx=[] … … 586 649 if self.dy==None: 587 650 self.dy=numpy.zeros(len(self.y)) 588 if (self. transy== "log10(y)" ):651 if (self.yLabel == "log10(y)" ): 589 652 for i in range(len(self.x)): 590 653 try: … … 598 661 print sys.exc_value 599 662 pass 600 601 self.x=[] 602 self.dx=[] 603 self.y=[] 604 self.dy=[] 605 self.x=tempx 606 self.y=tempy 607 self.dx=tempdx 608 self.dy=tempdy 663 664 self.x = tempx 665 self.y = tempy 666 self.dx = tempdx 667 self.dy = tempdy 609 668 610 669 def onFitRangeView(self,xmin=None,xmax=None): 670 """ 671 It limits View data range to plot from min to max 672 @param xmin: the minimum value of x to plot. 673 @param xmax: the maximum value of x to plot 674 """ 611 675 tempx=[] 612 676 tempdx=[] … … 676 740 The title is the name that will show up on the legend. 677 741 """ 678 self.name= "theo "742 self.name= "theory" 679 743 self.x = x 680 744 self.y = y … … 683 747 self.yaxis( 'intensity', 'cm') 684 748 self.view = self.View(self.x, self.y, None, self.dy) 749 685 750 def render(self,plot,**kw): 686 751 #plot.curve(self.x,self.y,dy=self.dy,**kw)
Note: See TracChangeset
for help on using the changeset viewer.