[52b1f77] | 1 | import wx.lib.newevent |
---|
[2bf92f2] | 2 | import matplotlib |
---|
| 3 | matplotlib.interactive(False) |
---|
| 4 | #Use the WxAgg back end. The Wx one takes too long to render |
---|
| 5 | matplotlib.use('WXAgg') |
---|
| 6 | from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg |
---|
| 7 | from matplotlib.figure import Figure |
---|
| 8 | import os |
---|
[52b1f77] | 9 | import fittings |
---|
[831149e] | 10 | import transform |
---|
[2bf92f2] | 11 | from canvas import FigureCanvas |
---|
[f193585] | 12 | from matplotlib.widgets import RectangleSelector |
---|
| 13 | from pylab import gca, gcf |
---|
| 14 | |
---|
[2bf92f2] | 15 | #TODO: make the plottables interactive |
---|
| 16 | |
---|
[52b1f77] | 17 | from plottables import Graph |
---|
| 18 | #(FuncFitEvent, EVT_FUNC_FIT) = wx.lib.newevent.NewEvent() |
---|
| 19 | import math,pylab |
---|
[2bf92f2] | 20 | def show_tree(obj,d=0): |
---|
| 21 | """Handy function for displaying a tree of graph objects""" |
---|
| 22 | print "%s%s" % ("-"*d,obj.__class__.__name__) |
---|
| 23 | if 'get_children' in dir(obj): |
---|
| 24 | for a in obj.get_children(): show_tree(a,d+1) |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | class PlotPanel(wx.Panel): |
---|
| 29 | """ |
---|
| 30 | The PlotPanel has a Figure and a Canvas. OnSize events simply set a |
---|
| 31 | flag, and the actually redrawing of the |
---|
| 32 | figure is triggered by an Idle event. |
---|
| 33 | """ |
---|
| 34 | def __init__(self, parent, id = -1, color = None,\ |
---|
| 35 | dpi = None, **kwargs): |
---|
| 36 | wx.Panel.__init__(self, parent, id = id, **kwargs) |
---|
[52b1f77] | 37 | self.parent = parent |
---|
[2bf92f2] | 38 | self.figure = Figure(None, dpi) |
---|
| 39 | #self.figure = pylab.Figure(None, dpi) |
---|
| 40 | #self.canvas = NoRepaintCanvas(self, -1, self.figure) |
---|
| 41 | self.canvas = FigureCanvas(self, -1, self.figure) |
---|
| 42 | self.SetColor(color) |
---|
| 43 | #self.Bind(wx.EVT_IDLE, self._onIdle) |
---|
| 44 | #self.Bind(wx.EVT_SIZE, self._onSize) |
---|
| 45 | self._resizeflag = True |
---|
| 46 | self._SetSize() |
---|
| 47 | self.subplot = self.figure.add_subplot(111) |
---|
| 48 | self.figure.subplots_adjust(left=.2, bottom=.2) |
---|
| 49 | self.yscale = 'linear' |
---|
[52b1f77] | 50 | self.xscale = 'linear' |
---|
[2bf92f2] | 51 | sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 52 | sizer.Add(self.canvas,1,wx.EXPAND) |
---|
| 53 | self.SetSizer(sizer) |
---|
[f193585] | 54 | |
---|
[057210c] | 55 | # Graph object to manage the plottables |
---|
| 56 | self.graph = Graph() |
---|
[52b1f77] | 57 | #self.Bind(EVT_FUNC_FIT, self.onFitRange) |
---|
[2bf92f2] | 58 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
[52b1f77] | 59 | #self.Bind(EVT_PROPERTY, self._onEVT_FUNC_PROPERTY) |
---|
[2bf92f2] | 60 | # Define some constants |
---|
| 61 | self.colorlist = ['b','g','r','c','m','y'] |
---|
| 62 | self.symbollist = ['o','x','^','v','<','>','+','s','d','D','h','H','p'] |
---|
[52b1f77] | 63 | #User scale |
---|
[f52bea1] | 64 | self.xscales ="x" |
---|
[831149e] | 65 | self.yscales ="log10(y)" |
---|
[dfca3de] | 66 | self.viewModel ="--" |
---|
[e2914b1] | 67 | # keep track if the previous transformation of x and y in Property dialog |
---|
| 68 | self.prevXtrans =" " |
---|
[46693050] | 69 | |
---|
[e2914b1] | 70 | self.prevYtrans =" " |
---|
[7a03e65] | 71 | |
---|
[f52bea1] | 72 | def returnTrans(self): |
---|
| 73 | return self.xscales,self.yscales |
---|
[dfca3de] | 74 | |
---|
[e2914b1] | 75 | def setTrans(self,xtrans,ytrans): |
---|
| 76 | """ |
---|
| 77 | @param xtrans: set x transformation on Property dialog |
---|
| 78 | @param ytrans: set y transformation on Property dialog |
---|
| 79 | """ |
---|
| 80 | self.prevXtrans =xtrans |
---|
| 81 | self.prevYtrans =ytrans |
---|
[dfca3de] | 82 | |
---|
[52b1f77] | 83 | def onFitting(self, event): |
---|
[e2914b1] | 84 | """ |
---|
| 85 | when clicking on linear Fit on context menu , display Fitting Dialog |
---|
| 86 | """ |
---|
[52b1f77] | 87 | list =[] |
---|
| 88 | list = self.graph.returnPlottable() |
---|
| 89 | from fitDialog import LinearFit |
---|
[7a03e65] | 90 | |
---|
[52b1f77] | 91 | if len(list.keys())>0: |
---|
| 92 | first_item = list.keys()[0] |
---|
[f52bea1] | 93 | dlg = LinearFit( None, first_item, self.onFitDisplay,self.returnTrans, -1, 'Fitting') |
---|
[52b1f77] | 94 | dlg.ShowModal() |
---|
| 95 | |
---|
| 96 | def _onProperties(self, event): |
---|
[e2914b1] | 97 | """ |
---|
| 98 | when clicking on Properties on context menu ,The Property dialog is displayed |
---|
| 99 | The user selects a transformation for x or y value and a new plot is displayed |
---|
| 100 | """ |
---|
[52b1f77] | 101 | from PropertyDialog import Properties |
---|
| 102 | dial = Properties(self, -1, 'Properties') |
---|
[dfca3de] | 103 | dial.setValues( self.prevXtrans, self.prevYtrans,self.viewModel ) |
---|
[52b1f77] | 104 | if dial.ShowModal() == wx.ID_OK: |
---|
[dfca3de] | 105 | self.xscales, self.yscales,self.viewModel = dial.getValues() |
---|
| 106 | if self.viewModel =="Guinier lny vs x^(2)": |
---|
| 107 | self.xscales="x^(2)" |
---|
| 108 | self.yscales="ln(y)" |
---|
| 109 | self.viewModel = "--" |
---|
| 110 | dial.setValues( self.xscales, self.yscales,self.viewModel ) |
---|
[52b1f77] | 111 | self._onEVT_FUNC_PROPERTY() |
---|
| 112 | dial.Destroy() |
---|
[831149e] | 113 | |
---|
[2bf92f2] | 114 | def set_yscale(self, scale='linear'): |
---|
[e2914b1] | 115 | """ |
---|
| 116 | Set the scale on Y-axis |
---|
| 117 | @param scale: the scale of y-axis |
---|
| 118 | """ |
---|
[2bf92f2] | 119 | self.subplot.set_yscale(scale) |
---|
| 120 | self.yscale = scale |
---|
| 121 | |
---|
| 122 | def get_yscale(self): |
---|
[e2914b1] | 123 | """ |
---|
| 124 | @return: Y-axis scale |
---|
| 125 | """ |
---|
[2bf92f2] | 126 | return self.yscale |
---|
[52b1f77] | 127 | |
---|
| 128 | def set_xscale(self, scale='linear'): |
---|
[e2914b1] | 129 | """ |
---|
| 130 | Set the scale on x-axis |
---|
| 131 | @param scale: the scale of x-axis |
---|
| 132 | """ |
---|
[52b1f77] | 133 | self.subplot.set_xscale(scale) |
---|
| 134 | self.xscale = scale |
---|
[e2914b1] | 135 | |
---|
[52b1f77] | 136 | def get_xscale(self): |
---|
[e2914b1] | 137 | """ |
---|
| 138 | @return: x-axis scale |
---|
| 139 | """ |
---|
[52b1f77] | 140 | return self.xscale |
---|
[2bf92f2] | 141 | |
---|
| 142 | def SetColor(self, rgbtuple): |
---|
| 143 | """Set figure and canvas colours to be the same""" |
---|
| 144 | if not rgbtuple: |
---|
| 145 | rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get() |
---|
| 146 | col = [c/255.0 for c in rgbtuple] |
---|
| 147 | self.figure.set_facecolor(col) |
---|
| 148 | self.figure.set_edgecolor(col) |
---|
| 149 | self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple)) |
---|
| 150 | |
---|
| 151 | def _onSize(self, event): |
---|
| 152 | self._resizeflag = True |
---|
| 153 | |
---|
| 154 | def _onIdle(self, evt): |
---|
| 155 | if self._resizeflag: |
---|
| 156 | self._resizeflag = False |
---|
| 157 | self._SetSize() |
---|
| 158 | self.draw() |
---|
| 159 | |
---|
| 160 | def _SetSize(self, pixels = None): |
---|
| 161 | """ |
---|
| 162 | This method can be called to force the Plot to be a desired size, which defaults to |
---|
| 163 | the ClientSize of the panel |
---|
| 164 | """ |
---|
| 165 | if not pixels: |
---|
| 166 | pixels = self.GetClientSize() |
---|
| 167 | self.canvas.SetSize(pixels) |
---|
| 168 | self.figure.set_size_inches(pixels[0]/self.figure.get_dpi(), |
---|
| 169 | pixels[1]/self.figure.get_dpi()) |
---|
| 170 | |
---|
| 171 | def draw(self): |
---|
| 172 | """Where the actual drawing happens""" |
---|
| 173 | self.figure.canvas.draw_idle() |
---|
| 174 | |
---|
| 175 | |
---|
[f193585] | 176 | |
---|
| 177 | |
---|
| 178 | def onselect(self,event1, event2): |
---|
| 179 | print"went here" |
---|
| 180 | from matplotlib.widgets import RectangleSelector |
---|
| 181 | from pylab import show, gca, gcf |
---|
[2bf92f2] | 182 | |
---|
[f193585] | 183 | 'event1 and event2 are the press and release events' |
---|
| 184 | x1, y1 = event1.xdata, event1.ydata |
---|
| 185 | x2, y2 = event2.xdata, event2.ydata |
---|
| 186 | print "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2) |
---|
| 187 | print " The button you used were: ",event1.button, event2.button |
---|
| 188 | gca().set_xlim([x1,x2]) |
---|
| 189 | gca().set_ylim([y1,y2]) |
---|
| 190 | gcf().canvas.draw_idle() |
---|
| 191 | |
---|
| 192 | # drawtype is 'box' or 'line' or 'none' |
---|
| 193 | LS = RectangleSelector(self.subplot, onselect,drawtype='box',useblit=True) |
---|
| 194 | show() |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | |
---|
[2bf92f2] | 199 | def onSaveImage(self, evt): |
---|
| 200 | #figure.savefig |
---|
[7a03e65] | 201 | #print "Save image not implemented" |
---|
[2bf92f2] | 202 | path = None |
---|
| 203 | dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.png", wx.SAVE) |
---|
| 204 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 205 | path = dlg.GetPath() |
---|
| 206 | mypath = os.path.basename(path) |
---|
| 207 | print path |
---|
| 208 | dlg.Destroy() |
---|
| 209 | if not path == None: |
---|
| 210 | self.subplot.figure.savefig(path,dpi=300, facecolor='w', edgecolor='w', |
---|
| 211 | orentation='portrait', papertype=None, format='png') |
---|
| 212 | |
---|
| 213 | def onContextMenu(self, event): |
---|
| 214 | """ |
---|
| 215 | Default context menu for a plot panel |
---|
| 216 | """ |
---|
| 217 | # Slicer plot popup menu |
---|
| 218 | slicerpop = wx.Menu() |
---|
| 219 | slicerpop.Append(313,'&Save image', 'Save image as PNG') |
---|
| 220 | wx.EVT_MENU(self, 313, self.onSaveImage) |
---|
[bceddd6] | 221 | |
---|
[52b1f77] | 222 | slicerpop.Append(316, '&Load 1D data file') |
---|
| 223 | wx.EVT_MENU(self, 316, self._onLoad1DData) |
---|
[bceddd6] | 224 | |
---|
[52b1f77] | 225 | slicerpop.AppendSeparator() |
---|
| 226 | slicerpop.Append(315, '&Properties') |
---|
[bceddd6] | 227 | wx.EVT_MENU(self, 315, self._onProperties) |
---|
[52b1f77] | 228 | |
---|
| 229 | slicerpop.AppendSeparator() |
---|
| 230 | slicerpop.Append(317, '&Linear Fit') |
---|
| 231 | wx.EVT_MENU(self, 317, self.onFitting) |
---|
| 232 | |
---|
[2bf92f2] | 233 | pos = event.GetPosition() |
---|
| 234 | pos = self.ScreenToClient(pos) |
---|
| 235 | self.PopupMenu(slicerpop, pos) |
---|
| 236 | |
---|
| 237 | ## The following is plottable functionality |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | def properties(self,prop): |
---|
| 241 | """Set some properties of the graph. |
---|
| 242 | |
---|
| 243 | The set of properties is not yet determined. |
---|
| 244 | """ |
---|
| 245 | # The particulars of how they are stored and manipulated (e.g., do |
---|
| 246 | # we want an inventory internally) is not settled. I've used a |
---|
| 247 | # property dictionary for now. |
---|
| 248 | # |
---|
| 249 | # How these properties interact with a user defined style file is |
---|
| 250 | # even less clear. |
---|
| 251 | |
---|
| 252 | # Properties defined by plot |
---|
| 253 | self.subplot.set_xlabel(r"$%s$" % prop["xlabel"]) |
---|
| 254 | self.subplot.set_ylabel(r"$%s$" % prop["ylabel"]) |
---|
| 255 | self.subplot.set_title(prop["title"]) |
---|
| 256 | |
---|
| 257 | # Properties defined by user |
---|
| 258 | #self.axes.grid(True) |
---|
| 259 | |
---|
| 260 | def clear(self): |
---|
| 261 | """Reset the plot""" |
---|
| 262 | |
---|
| 263 | # TODO: Redraw is brutal. Render to a backing store and swap in |
---|
| 264 | # TODO: rather than redrawing on the fly. |
---|
| 265 | self.subplot.clear() |
---|
| 266 | self.subplot.hold(True) |
---|
[f193585] | 267 | |
---|
[2bf92f2] | 268 | def render(self): |
---|
| 269 | """Commit the plot after all objects are drawn""" |
---|
| 270 | # TODO: this is when the backing store should be swapped in. |
---|
| 271 | from matplotlib.font_manager import FontProperties |
---|
| 272 | self.subplot.legend(prop=FontProperties(size=10)) |
---|
| 273 | #self.subplot.legend() |
---|
| 274 | pass |
---|
| 275 | |
---|
| 276 | def xaxis(self,label,units): |
---|
| 277 | """xaxis label and units. |
---|
| 278 | |
---|
| 279 | Axis labels know about units. |
---|
| 280 | |
---|
| 281 | We need to do this so that we can detect when axes are not |
---|
| 282 | commesurate. Currently this is ignored other than for formatting |
---|
| 283 | purposes. |
---|
| 284 | """ |
---|
| 285 | if units != "": label = label + " (" + units + ")" |
---|
| 286 | self.subplot.set_xlabel(label) |
---|
| 287 | pass |
---|
| 288 | |
---|
| 289 | def yaxis(self,label,units): |
---|
| 290 | """yaxis label and units.""" |
---|
| 291 | if units != "": label = label + " (" + units + ")" |
---|
| 292 | self.subplot.set_ylabel(label) |
---|
| 293 | pass |
---|
| 294 | |
---|
| 295 | def _connect_to_xlim(self,callback): |
---|
| 296 | """Bind the xlim change notification to the callback""" |
---|
| 297 | def process_xlim(axes): |
---|
| 298 | lo,hi = subplot.get_xlim() |
---|
| 299 | callback(lo,hi) |
---|
| 300 | self.subplot.callbacks.connect('xlim_changed',process_xlim) |
---|
| 301 | |
---|
| 302 | #def connect(self,trigger,callback): |
---|
| 303 | # print "PlotPanel.connect???" |
---|
| 304 | # if trigger == 'xlim': self._connect_to_xlim(callback) |
---|
| 305 | |
---|
| 306 | def points(self,x,y,dx=None,dy=None,color=0,symbol=0,label=None): |
---|
| 307 | """Draw markers with error bars""" |
---|
| 308 | self.subplot.set_yscale('linear') |
---|
[52b1f77] | 309 | self.subplot.set_xscale('linear') |
---|
[2bf92f2] | 310 | # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] |
---|
| 311 | if dx != None and type(dx) == type(()): |
---|
| 312 | dx = nx.vstack((x-dx[0],dx[1]-x)).transpose() |
---|
| 313 | if dy != None and type(dy) == type(()): |
---|
| 314 | dy = nx.vstack((y-dy[0],dy[1]-y)).transpose() |
---|
| 315 | |
---|
| 316 | if dx==None and dy==None: |
---|
| 317 | h = self.subplot.plot(x,y,color=self._color(color), |
---|
| 318 | marker=self._symbol(symbol),linestyle='',label=label) |
---|
| 319 | else: |
---|
| 320 | self.subplot.errorbar(x, y, yerr=dy, xerr=None, |
---|
[52b1f77] | 321 | ecolor=self._color(color), capsize=2,linestyle='', barsabove=False, |
---|
[2bf92f2] | 322 | marker=self._symbol(symbol), |
---|
| 323 | lolims=False, uplims=False, |
---|
[52b1f77] | 324 | xlolims=False, xuplims=False,label=label) |
---|
[2bf92f2] | 325 | |
---|
| 326 | self.subplot.set_yscale(self.yscale) |
---|
[52b1f77] | 327 | self.subplot.set_xscale(self.xscale) |
---|
[2bf92f2] | 328 | |
---|
| 329 | def curve(self,x,y,dy=None,color=0,symbol=0,label=None): |
---|
| 330 | """Draw a line on a graph, possibly with confidence intervals.""" |
---|
| 331 | c = self._color(color) |
---|
| 332 | self.subplot.set_yscale('linear') |
---|
[52b1f77] | 333 | self.subplot.set_xscale('linear') |
---|
[2bf92f2] | 334 | |
---|
| 335 | hlist = self.subplot.plot(x,y,color=c,marker='',linestyle='-',label=label) |
---|
| 336 | |
---|
| 337 | self.subplot.set_yscale(self.yscale) |
---|
[52b1f77] | 338 | self.subplot.set_xscale(self.xscale) |
---|
[2bf92f2] | 339 | |
---|
| 340 | def _color(self,c): |
---|
| 341 | """Return a particular colour""" |
---|
| 342 | return self.colorlist[c%len(self.colorlist)] |
---|
| 343 | |
---|
| 344 | def _symbol(self,s): |
---|
| 345 | """Return a particular symbol""" |
---|
| 346 | return self.symbollist[s%len(self.symbollist)] |
---|
[52b1f77] | 347 | |
---|
| 348 | def _onEVT_FUNC_PROPERTY(self): |
---|
| 349 | """ |
---|
[8cebf9b] | 350 | Receive the x and y transformation from myDialog,Transforms x and y in View |
---|
| 351 | and set the scale |
---|
[52b1f77] | 352 | """ |
---|
| 353 | list =[] |
---|
| 354 | list = self.graph.returnPlottable() |
---|
[f193585] | 355 | |
---|
[52b1f77] | 356 | for item in list: |
---|
[f193585] | 357 | item.getTransform(self.xscales,self.yscales) |
---|
[52b1f77] | 358 | if ( self.xscales=="x" ): |
---|
[f193585] | 359 | item.returnTransformationx(transform.toX,transform.errToX) |
---|
| 360 | |
---|
[52b1f77] | 361 | self.set_xscale("linear") |
---|
[f52bea1] | 362 | name, units = item.get_xaxis() |
---|
| 363 | self.graph.xaxis("%s" % name, "%s^{-1}" % units) |
---|
[52b1f77] | 364 | |
---|
| 365 | if ( self.xscales=="x^(2)" ): |
---|
[f193585] | 366 | item.returnTransformationx(transform.toX2,transform.errToX2) |
---|
[52b1f77] | 367 | self.set_xscale('linear') |
---|
[f52bea1] | 368 | name, units = item.get_xaxis() |
---|
| 369 | self.graph.xaxis("%s^{2}" % name, "%s^{-2}" % units) |
---|
[52b1f77] | 370 | |
---|
[831149e] | 371 | if (self.xscales=="log10(x)" ): |
---|
[f193585] | 372 | item.returnTransformationx(transform.toX,transform.errToX) |
---|
[8cebf9b] | 373 | self.set_xscale("log") |
---|
[f193585] | 374 | name, units = item.get_xaxis() |
---|
[35891ce] | 375 | self.graph.xaxis("Log10 %s" % name, "%s^{-1}" % units) |
---|
[52b1f77] | 376 | |
---|
[831149e] | 377 | if ( self.yscales=="ln(y)" ): |
---|
[f193585] | 378 | item.returnTransformationy(transform.toLogX,transform.errToLogX) |
---|
[831149e] | 379 | self.set_yscale("linear") |
---|
| 380 | name, units = item.get_yaxis() |
---|
[f193585] | 381 | item.check_data_PlottableY() |
---|
[35891ce] | 382 | self.graph.yaxis("log %s" % name, "%s^{-1}" % units) |
---|
[831149e] | 383 | |
---|
[52b1f77] | 384 | if ( self.yscales=="y" ): |
---|
[f193585] | 385 | item.returnTransformationy(transform.toX,transform.errToX) |
---|
[52b1f77] | 386 | self.set_yscale("linear") |
---|
[f52bea1] | 387 | name, units = item.get_yaxis() |
---|
| 388 | self.graph.yaxis("%s" % name, "%s^{-1}" % units) |
---|
[52b1f77] | 389 | |
---|
[831149e] | 390 | if ( self.yscales=="log10(y)" ): |
---|
[f193585] | 391 | item.returnTransformationy(transform.toX,transform.errToX) |
---|
| 392 | item.check_data_PlottableY() |
---|
[52b1f77] | 393 | self.set_yscale("log") |
---|
[f52bea1] | 394 | name, units = item.get_yaxis() |
---|
[35891ce] | 395 | self.graph.yaxis("Log10 %s" % name, "%s^{-1}" % units) |
---|
[52b1f77] | 396 | |
---|
| 397 | if ( self.yscales=="y^(2)" ): |
---|
[f193585] | 398 | item.returnTransformationy( transform.toX2,transform.errToX2 ) |
---|
[52b1f77] | 399 | self.set_yscale("linear") |
---|
[f52bea1] | 400 | name, units = item.get_yaxis() |
---|
| 401 | self.graph.yaxis("%s^2" % name, "%s^{-2}" % units) |
---|
[35891ce] | 402 | |
---|
[3d3a0e5] | 403 | if ( self.yscales =="1/y"): |
---|
[f193585] | 404 | item.returnTransformationy(transform.toOneOverX,transform.errOneOverX ) |
---|
[3d3a0e5] | 405 | self.set_yscale("linear") |
---|
| 406 | name, units = item.get_yaxis() |
---|
| 407 | self.graph.yaxis("%s" % name, "%s" % units) |
---|
[35891ce] | 408 | |
---|
[3d3a0e5] | 409 | if ( self.yscales =="1/sqrt(y)" ): |
---|
[f193585] | 410 | item.returnTransformationy(transform.toOneOverSqrtX,transform.errOneOverSqrtX ) |
---|
[3d3a0e5] | 411 | self.set_yscale("linear") |
---|
| 412 | name, units = item.get_yaxis() |
---|
[f193585] | 413 | item.check_data_PlottableY() |
---|
[3d3a0e5] | 414 | self.graph.yaxis("%s" %name, "%s" % units) |
---|
[7a03e65] | 415 | |
---|
[831149e] | 416 | if ( self.yscales =="ln(y*x)"): |
---|
[f193585] | 417 | item.returnTransformationy( transform.toLogXY,transform.errToLogXY) |
---|
[7a03e65] | 418 | self.set_yscale("linear") |
---|
[3d3a0e5] | 419 | yname, yunits = item.get_yaxis() |
---|
| 420 | xname, xunits = item.get_xaxis() |
---|
[35891ce] | 421 | self.graph.yaxis("Log %s%s" % (yname,xname), "%s^{-1}%s^{-1}" % (yunits,xunits)) |
---|
[831149e] | 422 | |
---|
[8e44d51] | 423 | if ( self.yscales =="ln(y*x^(2))"): |
---|
[f193585] | 424 | item.returnTransformationy( transform.toLogYX2,transform.errToLogYX2) |
---|
[7a03e65] | 425 | self.set_yscale("linear") |
---|
[3d3a0e5] | 426 | yname, yunits = item.get_yaxis() |
---|
| 427 | xname, xunits = item.get_xaxis() |
---|
[f193585] | 428 | item.check_data_PlottableY() |
---|
[35891ce] | 429 | self.graph.yaxis("Log %s%s^{2}" % (yname,xname), "%s^{-1}%s^{-2}" % (yunits,xunits)) |
---|
[831149e] | 430 | |
---|
| 431 | if ( self.yscales =="ln(y*x^(4))"): |
---|
[f193585] | 432 | item.returnTransformationy(transform.toLogYX4,transform.errToLogYX4) |
---|
[831149e] | 433 | self.set_yscale("linear") |
---|
| 434 | yname, yunits = item.get_yaxis() |
---|
| 435 | xname, xunits = item.get_xaxis() |
---|
[35891ce] | 436 | self.graph.yaxis("Log %s%s^{4}" % (yname,xname), "%s^{-1}%s^{-4}" % (yunits,xunits)) |
---|
[dfca3de] | 437 | |
---|
| 438 | if ( self.viewModel == "Guinier lny vs x^(2)"): |
---|
[f193585] | 439 | item.returnTransformationx(transform.toX2,transform.errToX2) |
---|
[dfca3de] | 440 | self.set_xscale('linear') |
---|
| 441 | name, units = item.get_xaxis() |
---|
| 442 | self.graph.xaxis("%s^{2}" % name, "%s^{-2}" % units) |
---|
[f193585] | 443 | item.returnTransformationy(transform.toLogX,transform.errToLogX ) |
---|
[dfca3de] | 444 | self.set_yscale("linear") |
---|
| 445 | name, units = item.get_yaxis() |
---|
[46693050] | 446 | self.graph.yaxis("$Log %s$" % name, "%s^{-1}" % units) |
---|
[f193585] | 447 | |
---|
[35891ce] | 448 | #item.name = self.yscales+" vs " +self.xscales |
---|
[52b1f77] | 449 | self.prevXtrans = self.xscales |
---|
| 450 | self.prevYtrans = self.yscales |
---|
[f193585] | 451 | item.transformView() |
---|
[52b1f77] | 452 | self.graph.render(self) |
---|
| 453 | self.subplot.figure.canvas.draw_idle() |
---|
[46693050] | 454 | |
---|
[f193585] | 455 | def onFitDisplay(self, plottable): |
---|
[e2914b1] | 456 | """ |
---|
| 457 | Add a new plottable into the graph .In this case this plottable will be used |
---|
| 458 | to fit some data |
---|
| 459 | @param plottable: the plottable to plot |
---|
| 460 | """ |
---|
[46693050] | 461 | #Add the data to fit |
---|
[f193585] | 462 | |
---|
[52b1f77] | 463 | self.graph.add(plottable) |
---|
| 464 | self.graph.render(self) |
---|
[1fdb81d] | 465 | |
---|
[52b1f77] | 466 | self.subplot.figure.canvas.draw_idle() |
---|
[7a03e65] | 467 | self.graph.delete(plottable) |
---|
[f193585] | 468 | |
---|
| 469 | |
---|
| 470 | |
---|
[2bf92f2] | 471 | class NoRepaintCanvas(FigureCanvasWxAgg): |
---|
| 472 | """We subclass FigureCanvasWxAgg, overriding the _onPaint method, so that |
---|
| 473 | the draw method is only called for the first two paint events. After that, |
---|
| 474 | the canvas will only be redrawn when it is resized. |
---|
| 475 | """ |
---|
| 476 | def __init__(self, *args, **kwargs): |
---|
| 477 | FigureCanvasWxAgg.__init__(self, *args, **kwargs) |
---|
| 478 | self._drawn = 0 |
---|
| 479 | |
---|
| 480 | def _onPaint(self, evt): |
---|
| 481 | """ |
---|
| 482 | Called when wxPaintEvt is generated |
---|
| 483 | """ |
---|
| 484 | if not self._isRealized: |
---|
| 485 | self.realize() |
---|
| 486 | if self._drawn < 2: |
---|
| 487 | self.draw(repaint = False) |
---|
| 488 | self._drawn += 1 |
---|
| 489 | self.gui_repaint(drawDC=wx.PaintDC(self)) |
---|
| 490 | |
---|