- Timestamp:
- May 30, 2008 2:14:48 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:
- be0ea2a
- Parents:
- 6a8adb0
- Location:
- guitools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
rb6972a0f r052a66bc 34 34 @param unit: the unit of the data 35 35 """ 36 return unit 36 37 toks=re.match("^", unit) 37 38 if not toks==None: … … 136 137 #User scale 137 138 self.xLabel ="x" 138 self.yLabel =" log10(y)"139 self.yLabel ="y" 139 140 self.viewModel ="--" 140 141 # keep track if the previous transformation of x and y in Property dialog 141 self.prevXtrans =" 142 self.prevYtrans =" 142 self.prevXtrans ="x" 143 self.prevYtrans ="y" 143 144 self.canvas.mpl_connect('scroll_event',self.onWheel) 144 145 self.axes = [self.subplot] … … 157 158 self.ErrBvalue=None 158 159 self.Chivalue=None 160 159 161 def resetFitView(self): 160 162 """ … … 248 250 dlg.ShowModal() 249 251 252 def linear_plottable_fit(self, plot): 253 """ 254 when clicking on linear Fit on context menu , display Fitting Dialog 255 """ 256 from fitDialog import LinearFit 257 258 dlg = LinearFit( None, plot, self.onFitDisplay,self.returnTrans, -1, 'Linear Fit') 259 260 if (self.xmin !=0.0 )and ( self.xmax !=0.0)\ 261 and(self.xminView !=0.0 )and ( self.xmaxView !=0.0): 262 dlg.setFitRange(self.xminView,self.xmaxView,self.xmin,self.xmax) 263 dlg.ShowModal() 264 250 265 def _onProperties(self, event): 251 266 """ … … 356 371 """ 357 372 # Slicer plot popup menu 373 id = wx.NewId() 358 374 slicerpop = wx.Menu() 359 slicerpop.Append(313,'&Save image', 'Save image as PNG') 360 wx.EVT_MENU(self, 313, self.onSaveImage) 361 362 slicerpop.Append(316, '&Load 1D data file') 363 wx.EVT_MENU(self, 316, self._onLoad1DData) 375 slicerpop.Append(id,'&Save image', 'Save image as PNG') 376 wx.EVT_MENU(self, id, self.onSaveImage) 377 378 id = wx.NewId() 379 slicerpop.Append(id, '&Load 1D data file') 380 wx.EVT_MENU(self, id, self._onLoad1DData) 364 381 382 id = wx.NewId() 365 383 slicerpop.AppendSeparator() 366 slicerpop.Append(315, '&Properties') 367 wx.EVT_MENU(self, 315, self._onProperties) 368 384 slicerpop.Append(id, '&Properties') 385 wx.EVT_MENU(self, id, self._onProperties) 386 387 id = wx.NewId() 369 388 slicerpop.AppendSeparator() 370 slicerpop.Append(317, '&Linear Fit') 371 wx.EVT_MENU(self, 317, self.onFitting) 372 389 slicerpop.Append(id, '&Linear Fit') 390 wx.EVT_MENU(self, id, self.onFitting) 391 392 id = wx.NewId() 373 393 slicerpop.AppendSeparator() 374 slicerpop.Append( 318, '&Reset Graph')375 wx.EVT_MENU(self, 318, self.onResetGraph)394 slicerpop.Append(id, '&Reset Graph') 395 wx.EVT_MENU(self, id, self.onResetGraph) 376 396 377 397 pos = event.GetPosition() … … 452 472 self.subplot.set_yscale('linear') 453 473 self.subplot.set_xscale('linear') 474 454 475 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 455 476 if dx != None and type(dx) == type(()): … … 462 483 marker=self._symbol(symbol),linestyle='',label=label) 463 484 else: 485 col = self._color(color) 464 486 self.subplot.errorbar(x, y, yerr=dy, xerr=None, 465 ecolor=self._color(color), capsize=2,linestyle='', barsabove=False, 487 ecolor=col, capsize=2,linestyle='', barsabove=False, 488 mec=col, mfc=col, 466 489 marker=self._symbol(symbol), 467 490 lolims=False, uplims=False, … … 490 513 return self.symbollist[s%len(self.symbollist)] 491 514 492 def _onEVT_FUNC_PROPERTY(self): 515 def _replot(self): 516 """ 517 Rescale the plottables according to the latest 518 user selection and update the plot 519 """ 520 self.graph.reset_scale() 521 self._onEVT_FUNC_PROPERTY(remove_fit=False) 522 523 #TODO: Why do we have to have the following line? 524 self.fit_result.reset_view() 525 526 self.graph.render(self) 527 self.subplot.figure.canvas.draw_idle() 528 529 def _onEVT_FUNC_PROPERTY(self, remove_fit=True): 493 530 """ 494 531 Receive the x and y transformation from myDialog,Transforms x and y in View … … 497 534 list =[] 498 535 list = self.graph.returnPlottable() 499 self.fit_result.x =[] 500 self.fit_result.y =[] 501 self.fit_result.dx=None 502 self.fit_result.dy=None 536 537 if remove_fit: 538 self.fit_result.x =[] 539 self.fit_result.y =[] 540 self.fit_result.dx=None 541 self.fit_result.dy=None 542 self.graph.delete(self.fit_result) 503 543 504 544 for item in list: -
guitools/fitDialog.py
r6a8adb0 r052a66bc 13 13 Return a float in a standardized, human-readable formatted string 14 14 """ 15 try: 16 value = float(value) 17 except: 18 print "returning 0" 19 return "0" 20 15 21 if high: 16 22 return "%-6.4g" % value … … 130 136 iy += 1 131 137 ix = 0 132 sizer.Add(wx.StaticText(self, -1, ' Plottedrange'),(iy, ix),(1,1),\138 sizer.Add(wx.StaticText(self, -1, 'Maximum range'),(iy, ix),(1,1),\ 133 139 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 134 140 ix +=1 … … 190 196 191 197 if self.Avalue==None: 192 self.tcA.SetLabel( str(self.default_A))198 self.tcA.SetLabel(format_number(self.default_A)) 193 199 else : 194 self.tcA.SetLabel( str(self.Avalue))200 self.tcA.SetLabel(format_number(self.Avalue)) 195 201 if self.Bvalue==None: 196 self.tcB.SetLabel( str(self.default_B))202 self.tcB.SetLabel(format_number(self.default_B)) 197 203 else: 198 self.tcB.SetLabel( str(self.Bvalue))204 self.tcB.SetLabel(format_number(self.Bvalue)) 199 205 if self.ErrAvalue==None: 200 self.tcErrA.SetLabel( str(0.0))206 self.tcErrA.SetLabel(format_number(0.0)) 201 207 else: 202 self.tcErrA.SetLabel( str(self.ErrAvalue))208 self.tcErrA.SetLabel(format_number(self.ErrAvalue)) 203 209 if self.ErrBvalue==None: 204 self.tcErrB.SetLabel( str(0.0))210 self.tcErrB.SetLabel(format_number(0.0)) 205 211 else: 206 self.tcErrB.SetLabel( str(self.ErrBvalue))212 self.tcErrB.SetLabel(format_number(self.ErrBvalue)) 207 213 if self.Chivalue==None: 208 self.tcChi.SetLabel( str(0.0))214 self.tcChi.SetLabel(format_number(0.0)) 209 215 else: 210 self.tcChi.SetLabel( str(self.Chivalue))216 self.tcChi.SetLabel(format_number(self.Chivalue)) 211 217 if self.plottable.x !=[]: 212 218 self.mini =min(self.plottable.x) -
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.