Changeset 52b1f77 in sasview
- Timestamp:
- Apr 1, 2008 12:27:52 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:
- f79b054
- Parents:
- 8e4516f
- Location:
- guitools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r15f0e94 r52b1f77 1 import wx 1 import wx.lib.newevent 2 2 import matplotlib 3 3 matplotlib.interactive(False) … … 7 7 from matplotlib.figure import Figure 8 8 import os 9 9 import fittings 10 10 from canvas import FigureCanvas 11 11 #TODO: make the plottables interactive 12 12 13 from plottables import Graph 13 14 #(FuncFitEvent, EVT_FUNC_FIT) = wx.lib.newevent.NewEvent() 15 import math,pylab 14 16 def show_tree(obj,d=0): 15 17 """Handy function for displaying a tree of graph objects""" … … 29 31 dpi = None, **kwargs): 30 32 wx.Panel.__init__(self, parent, id = id, **kwargs) 31 33 self.parent = parent 32 34 self.figure = Figure(None, dpi) 33 35 #self.figure = pylab.Figure(None, dpi) … … 42 44 self.figure.subplots_adjust(left=.2, bottom=.2) 43 45 self.yscale = 'linear' 44 46 self.xscale = 'linear' 45 47 sizer = wx.BoxSizer(wx.VERTICAL) 46 48 sizer.Add(self.canvas,1,wx.EXPAND) … … 49 51 # Graph object to manage the plottables 50 52 self.graph = Graph() 51 53 #self.Bind(EVT_FUNC_FIT, self.onFitRange) 52 54 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 53 55 #self.Bind(EVT_PROPERTY, self._onEVT_FUNC_PROPERTY) 54 56 # Define some constants 55 57 self.colorlist = ['b','g','r','c','m','y'] 56 58 self.symbollist = ['o','x','^','v','<','>','+','s','d','D','h','H','p'] 59 #User scale 60 self.xscales ="" 61 self.yscales ="" 62 # keep track if the previous transformation 63 self.prevXtrans ="x" 64 self.prevYtrans ="Log(y)" 65 66 def onFitting(self, event): 67 list =[] 68 list = self.graph.returnPlottable() 69 from fitDialog import LinearFit 70 71 print len(list) 72 if len(list.keys())>0: 73 first_item = list.keys()[0] 74 print first_item, list[first_item].__class__.__name__ 75 dlg = LinearFit( None, first_item, self.onFitDisplay, -1, 'Fitting') 76 dlg.ShowModal() 77 78 def _onProperties(self, event): 79 80 from PropertyDialog import Properties 81 dial = Properties(self, -1, 'Properties') 82 if dial.ShowModal() == wx.ID_OK: 83 self.xscales, self.yscales = dial.getValues() 84 self._onEVT_FUNC_PROPERTY() 85 dial.Destroy() 86 87 def toX(self,x): 88 return x 89 90 def toX2(self,x): 91 """ 92 Calculate x^(2) 93 @param x: float value 94 """ 95 return math.pow(x,2) 96 def fromX2(self,x): 97 """ 98 Calculate square root of x 99 @param x: float value 100 """ 101 if x >=0 : 102 return math.sqrt(x) 103 else: 104 return 0 105 def toLogXY(self,x): 106 """ 107 calculate log x 108 @param x: float value 109 """ 110 if x > 0: 111 return math.log(x) 112 else: 113 return 0 114 def fromLogXY(self,x): 115 """ 116 Calculate e^(x) 117 @param x: float value 118 """ 119 if x.__class__.__name__ == 'list': 120 temp =[] 121 for x_i in x: 122 temp.append(math.exp(x_i)) 123 return temp 124 else: 125 return math.exp(x) 126 57 127 58 128 def set_yscale(self, scale='linear'): … … 62 132 def get_yscale(self): 63 133 return self.yscale 134 135 def set_xscale(self, scale='linear'): 136 self.subplot.set_xscale(scale) 137 self.xscale = scale 138 139 def get_xscale(self): 140 return self.xscale 64 141 65 142 def SetColor(self, rgbtuple): … … 120 197 slicerpop.Append(313,'&Save image', 'Save image as PNG') 121 198 wx.EVT_MENU(self, 313, self.onSaveImage) 122 199 slicerpop.Append(316, '&Load 1D data file') 200 201 wx.EVT_MENU(self, 314, self.onSave1DData) 202 wx.EVT_MENU(self, 316, self._onLoad1DData) 203 slicerpop.AppendSeparator() 204 slicerpop.Append(315, '&Properties') 205 206 slicerpop.AppendSeparator() 207 slicerpop.Append(317, '&Linear Fit') 208 209 wx.EVT_MENU(self, 314, self.onSave1DData) 210 wx.EVT_MENU(self, 316, self._onLoad1DData) 211 wx.EVT_MENU(self, 315, self._onProperties) 212 wx.EVT_MENU(self, 317, self.onFitting) 213 123 214 pos = event.GetPosition() 124 215 pos = self.ScreenToClient(pos) … … 199 290 """Draw markers with error bars""" 200 291 self.subplot.set_yscale('linear') 292 self.subplot.set_xscale('linear') 201 293 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 202 294 if dx != None and type(dx) == type(()): … … 209 301 marker=self._symbol(symbol),linestyle='',label=label) 210 302 else: 211 col = self._color(color)212 303 self.subplot.errorbar(x, y, yerr=dy, xerr=None, 213 ecolor= col, capsize=2,linestyle='', barsabove=False,304 ecolor=self._color(color), capsize=2,linestyle='', barsabove=False, 214 305 marker=self._symbol(symbol), 215 306 lolims=False, uplims=False, 216 xlolims=False, xuplims=False,label=label, 217 mec = col, mfc = col) 307 xlolims=False, xuplims=False,label=label) 218 308 219 309 self.subplot.set_yscale(self.yscale) 310 self.subplot.set_xscale(self.xscale) 220 311 221 312 def curve(self,x,y,dy=None,color=0,symbol=0,label=None): … … 223 314 c = self._color(color) 224 315 self.subplot.set_yscale('linear') 316 self.subplot.set_xscale('linear') 225 317 226 318 hlist = self.subplot.plot(x,y,color=c,marker='',linestyle='-',label=label) 227 319 228 320 self.subplot.set_yscale(self.yscale) 321 self.subplot.set_xscale(self.xscale) 229 322 230 323 def _color(self,c): … … 235 328 """Return a particular symbol""" 236 329 return self.symbollist[s%len(self.symbollist)] 237 238 239 240 330 331 def _onEVT_FUNC_PROPERTY(self): 332 """ 333 Receive the scale from myDialog and set the scale 334 """ 335 list =[] 336 list = self.graph.returnPlottable() 337 for item in list: 338 if ( self.xscales=="x" ): 339 if self.prevXtrans == "x^(2)": 340 item.transform_x( self.fromX2, self.errFunc ) 341 #elif self.prevXtrans == "Log(x)" 342 #item.transform_x( self.fromLogXY,self.errFunc ) 343 print "Values of x",item.x[0:5] 344 print "Values of view x",item.view.x[0:5] 345 self.set_xscale("linear") 346 self.graph.xaxis('\\rm{q} ', 'A^{-1}') 347 348 if ( self.xscales=="x^(2)" ): 349 #if self.prevXtrans == "Log(x)": 350 #item.transform_x( self.fromLogXY, self.errFunc ) 351 if self.prevXtrans != "x^(2)": 352 item.transform_x( self.toX2, self.errFunc ) 353 print "Values of x",item.x[0:5] 354 print "Values of view x^(2)",item.view.x[0:5] 355 self.set_xscale('linear') 356 self.graph.xaxis('\\rm{q^{2}} ', 'A^{-2}') 357 358 if (self.xscales=="Log(x)" ): 359 if self.prevXtrans == "x^(2)": 360 item.transform_x( self.fromX2, self.errFunc ) 361 #elif self.prevXtrans == "Log(x)": 362 #item.transform_x( self.toLogXY, self.errFunc ) 363 #self.set_xscale("linear") 364 self.set_xscale('log') 365 self.graph.xaxis('\\rm{log(q)} ', 'A^{-1}') 366 367 if ( self.yscales=="y" ): 368 if self.prevYtrans == "y^(2)": 369 item.transform_y( self.toX2, self.errFunc ) 370 #elif self.prevXtrans == "Log(y)" 371 #item.transform_y( self.fromLogXY.errFunc ) 372 self.set_yscale("linear") 373 self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 374 375 if ( self.yscales=="Log(y)" ): 376 if self.prevYtrans == "y^(2)": 377 item.transform_y( self.fromX2, self.errFunc ) 378 #elif self.prevYtrans != "Log(y)": 379 #item.transform_y( self.toLogXY, self.errFunc ) 380 #self.set_yscale("linear") 381 self.set_yscale("log") 382 self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 383 384 if ( self.yscales=="y^(2)" ): 385 #if self.prevYtrans == "Log(y)": 386 #item.transform_y( self.fromLogXY, self.errFunc ) 387 if self.prevYtrans != "y^(2)": 388 item.transform_y( self.toX2, self.errFunc ) 389 self.set_yscale("linear") 390 self.graph.yaxis("\\rm{Intensity^{2}} ","cm^{-2}") 391 item.set_View(item.x,item.y) 392 393 self.prevXtrans = self.xscales 394 self.prevYtrans = self.yscales 395 396 self.graph.render(self) 397 self.subplot.figure.canvas.draw_idle() 398 399 def errFunc(self,x): 400 """ 401 calculate log x 402 @param x: float value 403 """ 404 if x >=0: 405 return math.sqrt(x) 406 else: 407 return 0 408 409 410 def onFitDisplay(self, plottable): 411 self.graph.add(plottable) 412 self.graph.render(self) 413 self.subplot.figure.canvas.draw_idle() 414 415 241 416 class NoRepaintCanvas(FigureCanvasWxAgg): 242 417 """We subclass FigureCanvasWxAgg, overriding the _onPaint method, so that -
guitools/plottables.py
r8e4516f r52b1f77 199 199 200 200 return labels 201 201 202 def returnPlottable(self): 202 203 return self.plottables … … 335 336 def __init__(self): 336 337 self.view = View() 338 def set_View(self,x,y): 339 self.x= x 340 self.y = y 341 self.dx= x 342 self.dy = y 343 self.reset_view() 344 345 def reset_view(self): 346 self.view = self.View(self.x, self.y, self.dx, self.dy) 337 347 338 348 def render(self,plot): … … 344 354 that it makes sense. 345 355 """ 346 356 347 357 plot.xaxis(self._xaxis, self._xunit) 348 358 plot.yaxis(self._yaxis, self._yunit) … … 400 410 for i in range(len(x)): 401 411 self.x[i] = func(x[i]) 412 for i in range(len(dx)): 402 413 self.dx[i] = errfunc(dx[i]) 403 414 … … 416 427 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 417 428 418 self.y = deepcopy(y)419 self.dy = deepcopy(dy)429 self.y = copy.deepcopy(y) 430 self.dy = copy.deepcopy(dy) 420 431 421 432 for i in range(len(y)): 422 433 self.y[i] = func(y[i]) 434 for i in range(len(dy)): 423 435 self.dy[i] = errfunc(dy[i]) 424 425 426 436 427 437 class Data1D(Plottable): 428 438 """Data plottable: scatter plot of x,y with errors in x and y. … … 444 454 445 455 self.view = self.View(self.x, self.y, self.dx, self.dy) 446 456 447 457 def render(self,plot,**kw): 448 458 plot.points(self.view.x,self.view.y,dx=self.view.dx,dy=self.view.dy,**kw) 449 459 450 460 def changed(self): 451 461 return False … … 524 534 graph.add(Theory1D(x,y,dy=dy)) 525 535 526 return graph 536 return graph 527 537 528 538 def demo_plotter(graph):
Note: See TracChangeset
for help on using the changeset viewer.