Changeset 052a66bc in sasview for guitools/plottables.py
- Timestamp:
- May 30, 2008 2:14:48 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:
- be0ea2a
- Parents:
- 6a8adb0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/plottables.py
r05da1f89 r052a66bc 173 173 """Detect if any graphed plottables have changed""" 174 174 return any([p.changed() for p in self.plottables]) 175 176 def get_range(self): 177 """ 178 Return the range of all displayed plottables 179 """ 180 min = None 181 max = None 182 183 for p in self.plottables: 184 if p.hidden==True: 185 continue 186 187 if not p.x==None: 188 for x_i in p.x: 189 if min==None or x_i<min: 190 min = x_i 191 if max==None or x_i>max: 192 max = x_i 193 194 return min, max 175 195 176 196 def delete(self,plottable): … … 183 203 self.color =0 184 204 205 def reset_scale(self): 206 """ 207 Resets the scale transformation data to the underlying data 208 """ 209 for p in self.plottables: 210 p.reset_view() 185 211 186 212 def reset(self): … … 321 347 322 348 323 class Plottable: 349 class Plottable(object): 350 351 # Short ascii name to refer to the plottable in a menu 352 short_name = None 353 354 # Data 355 x = None 356 y = None 357 dx = None 358 dy = None 359 360 # Parameter to allow a plot to be part of the list without being displayed 361 hidden = False 362 363 def __setattr__(self, name, value): 364 """ 365 Take care of changes in View when data is changed. 366 This method is provided for backward compatibility. 367 """ 368 object.__setattr__(self, name, value) 369 370 if name in ['x', 'y', 'dx', 'dy']: 371 self.reset_view() 372 #print "self.%s has been called" % name 373 374 def set_data(self, x, y, dx=None, dy=None): 375 self.x = x 376 self.y = y 377 self.dy = dy 378 self.dx = dx 379 self.transformView() 380 324 381 def xaxis(self, name, units): 325 382 """ … … 409 466 plot.xaxis(self._xaxis, self._xunit) 410 467 plot.yaxis(self._yaxis, self._yunit) 468 469 def is_empty(self): 470 """ 471 Returns True if there is no data stored in the plottable 472 """ 473 if not self.x==None and len(self.x)==0 \ 474 and not self.y==None and len(self.y)==0: 475 return True 476 return False 477 411 478 412 479 def colors(self): … … 500 567 self.funcdx= None 501 568 self.funcdy= None 569 502 570 def transform(self, x=None,y=None,dx=None, dy=None): 503 571 """ … … 512 580 # Sanity check 513 581 # Do the transofrmation only when x and y are empty 582 has_err_x = not (dx==None or len(dx)==0) 583 has_err_y = not (dy==None or len(dy)==0) 584 514 585 if (x!=None) and (y!=None): 515 if dxand not len(x)==len(dx):586 if not dx==None and not len(dx)==0 and not len(x)==len(dx): 516 587 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 517 588 # Check length of y array … … 519 590 raise ValueError, "Plottable.View: Given y and x are not of the same length" 520 591 521 if dy and not len(y)==len(dy): 522 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 592 if not dy==None and not len(dy)==0 and not len(y)==len(dy): 593 message = "Plottable.View: Given y and dy are not of the same length: len(y)=%s, len(dy)=%s" %(len(y), len(dy)) 594 raise ValueError, message 595 596 523 597 self.x = [] 524 598 self.y = [] 525 self.dx = [] 526 self.dy = [] 599 if has_err_x: 600 self.dx = [] 601 else: 602 self.dx = None 603 if has_err_y: 604 self.dy = [] 605 else: 606 self.dy = None 527 607 tempx=[] 528 608 tempy=[] 529 if dx==None: 609 610 if not has_err_x: 530 611 dx=numpy.zeros(len(x)) 531 if dy==None:612 if not has_err_y: 532 613 dy=numpy.zeros(len(y)) 533 614 … … 536 617 tempx =self.funcx(x[i],y[i]) 537 618 tempy =self.funcy(y[i],x[i]) 538 tempdx = self.funcdx(x[i], y[i], dx[i], dy[i]) 539 tempdy = self.funcdy(y[i], x[i], dy[i], dx[i]) 619 if has_err_x: 620 tempdx = self.funcdx(x[i], y[i], dx[i], dy[i]) 621 if has_err_y: 622 tempdy = self.funcdy(y[i], x[i], dy[i], dx[i]) 540 623 541 624 self.x.append(tempx) 542 625 self.y.append(tempy) 543 self.dx.append(tempdx) 544 self.dy.append(tempdy) 626 if has_err_x: 627 self.dx.append(tempdx) 628 if has_err_y: 629 self.dy.append(tempdy) 545 630 except: 546 631 tempx=x[i] 547 632 tempy=y[i] 548 print "View.transform: skipping point x %g" % x[i] 549 print "View.transform: skipping point y %g" % y[i] 550 print "View.transform: skipping point dy %g" % dy[i] 633 print "View.transform: skipping point x=%g y=%g" % (x[i], y[i]) 551 634 552 635 print sys.exc_value 553 636 554 637 # Sanity check 555 if not (len(self.x)==len(self.dx))and(len(self.x)==len(self.dy))\ 556 and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 557 raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length" 638 if not len(self.x)==len(self.y): 639 raise ValueError, "Plottable.View: transformed x and y are not of the same length" 640 if has_err_x and not (len(self.x) and len(self.dx)): 641 raise ValueError, "Plottable.View: transformed x and dx are not of the same length" 642 if has_err_y and not (len(self.y) and len(self.dy)): 643 raise ValueError, "Plottable.View: transformed y and dy are not of the same length" 644 558 645 # Check that negative values are not plot on x and y axis for log10 transformation 559 646 self.check_data_logX() … … 564 651 self.DXreel = self.dx 565 652 self.DYreel = self.dy 566 567 653 568 654 … … 749 835 750 836 def render(self,plot,**kw): 751 #plot.curve(self.x,self.y,dy=self.dy,**kw)752 837 plot.curve(self.view.x,self.view.y,dy=self.view.dy,**kw) 753 838
Note: See TracChangeset
for help on using the changeset viewer.