55 |
units = instance.getType().getDimensions().getDefaultUnits() |
units = instance.getType().getDimensions().getDefaultUnits() |
56 |
|
|
57 |
uname = str(units.getName()) |
uname = str(units.getName()) |
58 |
if uname.find("/")!=-1: |
if len(uname) or uname.find("/")!=-1: |
59 |
uname = "["+uname+"]" |
uname = "["+uname+"]" |
60 |
|
|
61 |
if uname == "": |
if uname == "": |
192 |
self.rows = [] |
self.rows = [] |
193 |
self.activeiter = _store.append(None, [ObserverRow()] ) |
self.activeiter = _store.append(None, [ObserverRow()] ) |
194 |
|
|
195 |
|
def plot(self,x=None,y=None,y2=None): |
196 |
|
"""create a plot from two columns in the ObserverTable""" |
197 |
|
import platform |
198 |
|
import matplotlib |
199 |
|
matplotlib.use('GTKAgg') |
200 |
|
import pylab |
201 |
|
pylab.ioff() |
202 |
|
if x is None or y is None: |
203 |
|
if len(self.cols)<2: |
204 |
|
raise Exception("Not enough columns to plot (need 2+)") |
205 |
|
if x is None: |
206 |
|
x=self.cols[0] |
207 |
|
if y is None: |
208 |
|
y=self.cols[1] |
209 |
|
|
210 |
|
if x.__class__ is int and x>=0 and x<len(self.cols): |
211 |
|
x=self.cols[x] |
212 |
|
if y.__class__ is int and y>=0 and y<len(self.cols): |
213 |
|
y=self.cols[y] |
214 |
|
if y2.__class__ is int and y2>=0 and y2<len(self.cols): |
215 |
|
y2=self.cols[y2] |
216 |
|
|
217 |
|
ncols = 2 |
218 |
|
if y2 is not None: |
219 |
|
ncols+=1 |
220 |
|
|
221 |
|
A = pylab.zeros((len(self.rows),ncols),'f') |
222 |
|
for i in range(len(self.rows)): |
223 |
|
r = self.rows[i].get_values(self) |
224 |
|
A[i,0]=r[x.index] |
225 |
|
A[i,1]=r[y.index] |
226 |
|
if y2 is not None: |
227 |
|
A[i,2]=r[y2.index] |
228 |
|
print A |
229 |
|
pylab.figure() |
230 |
|
p1 = pylab.plot(A[:,0],A[:,1],'b-') |
231 |
|
pylab.xlabel(x.title) |
232 |
|
pylab.ylabel(y.title) |
233 |
|
|
234 |
|
if y2 is not None: |
235 |
|
ax2 = pylab.twinx() |
236 |
|
p2 = pylab.plot(A[:,0],A[:,2],'r-') |
237 |
|
pylab.ylabel(y2.title) |
238 |
|
ax2.yaxis.tick_right() |
239 |
|
pylab.legend([y.name,y2.name]) |
240 |
|
|
241 |
|
pylab.ion() |
242 |
|
if platform.system()=="Windows": |
243 |
|
pylab.show() |
244 |
|
else: |
245 |
|
pylab.show(False) |
246 |
|
|
247 |
|
def on_plot_clicked(self,*args): |
248 |
|
try: |
249 |
|
self.plot() |
250 |
|
except Exception,e: |
251 |
|
self.browser.reporter.reportError(str(e)) |
252 |
|
|
253 |
def do_add_row(self,values=None): |
def do_add_row(self,values=None): |
254 |
_store = self.view.get_model() |
_store = self.view.get_model() |
255 |
if self.alive: |
if self.alive: |
300 |
def copy_to_clipboard(self,clip): |
def copy_to_clipboard(self,clip): |
301 |
_s = [] |
_s = [] |
302 |
_s.append('\t'.join([_v.title for _k,_v in self.cols.iteritems()])) |
_s.append('\t'.join([_v.title for _k,_v in self.cols.iteritems()])) |
303 |
_cf = [_v.units.getConversion() for _k,_v in self.cols.iteritems()] |
#_cf = [_v.units.getConversion() for _k,_v in self.cols.iteritems()] |
304 |
print "COPYING %d ROWS" % len(self.rows) |
print "COPYING %d ROWS" % len(self.rows) |
305 |
print "CONVERSIONS:",_cf |
#print "CONVERSIONS:",_cf |
306 |
for _r in self.rows: |
for _r in self.rows: |
307 |
_s.append("\t".join([`_v` for _v in _r.get_values(self)])) |
_s.append("\t".join([`_v` for _v in _r.get_values(self)])) |
308 |
|
|