From 707307ca6420332e957b2dea25acb229d8078052 Mon Sep 17 00:00:00 2001 From: Sam Neymotin Date: Tue, 13 Nov 2018 17:11:13 -0500 Subject: [PATCH] make sure colors for external data always in same order; fix RMSE for individual data files --- __init__.py | 2 +- simdat.py | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/__init__.py b/__init__.py index 00a03ddd0..10e1b1a44 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1 @@ -__version__ = '0.0.8' +__version__ = '0.0.9' diff --git a/simdat.py b/simdat.py index 013c81707..f1c2df765 100644 --- a/simdat.py +++ b/simdat.py @@ -138,8 +138,9 @@ class SIMCanvas (FigureCanvas): def __init__ (self, paramf, parent=None, width=5, height=4, dpi=40, title='Simulation Viewer'): FigureCanvas.__init__(self, Figure(figsize=(width, height), dpi=dpi)) self.title = title - self.lextdatobj = [] - self.lpatch = [mpatches.Patch(color='black', label='Sim.')] + self.lextdatobj = [] # external data object + self.clridx = 5 # index for next color for drawing external data + self.lpatch = [mpatches.Patch(color='black', label='Sim.')] # legend for dipole signals self.setParent(parent) self.gui = parent FigureCanvas.setSizePolicy(self,QSizePolicy.Expanding,QSizePolicy.Expanding) @@ -330,6 +331,12 @@ def setupaxdipole (self): else: self.axdipole = ax = self.figure.add_subplot(self.G[gRow:-1,0]); # dipole + def getnextcolor (self): + # get next color for external data (colors selected in order) + self.clridx += 5 + if self.clridx > 100: self.clridx = 5 + return self.clridx + def plotextdat (self, recalcErr=True): # plot 'external' data (e.g. from experiment/other simulation) try: @@ -351,20 +358,20 @@ def plotextdat (self, recalcErr=True): self.clearlextdatobj() # clear annotation objects + ddx = 0 for fn,dat in ddat['dextdata'].items(): shp = dat.shape - for c in range(1,shp[1],1): - clr = csm.to_rgba(int(np.random.RandomState().uniform(5,101,1))) - self.lextdatobj.append(ax.plot(dat[:,0],dat[:,c],color=clr,linewidth=self.gui.linewidth+1)) - yl = ((min(yl[0],min(dat[:,c]))),(max(yl[1],max(dat[:,c])))) - - fx = int(shp[0] * float(c) / shp[1]) - - if lerr: - tx,ty=dat[fx,0],dat[fx,c] - txt='RMSE:' + str(round(lerr[c-1],2)) - self.lextdatobj.append(ax.annotate(txt,xy=(dat[0,0],dat[0,c]),xytext=(tx,ty),color=clr,fontweight='bold')) - self.lpatch.append(mpatches.Patch(color=clr, label=fn.split(os.path.sep)[-1].split('.txt')[0])) + clr = csm.to_rgba(self.getnextcolor()) + c = min(shp[1],1) + self.lextdatobj.append(ax.plot(dat[:,0],dat[:,c],color=clr,linewidth=self.gui.linewidth+1)) + yl = ((min(yl[0],min(dat[:,c]))),(max(yl[1],max(dat[:,c])))) + fx = int(shp[0] * float(c) / shp[1]) + if lerr: + tx,ty=dat[fx,0],dat[fx,c] + txt='RMSE:' + str(round(lerr[ddx],2)) + self.lextdatobj.append(ax.annotate(txt,xy=(dat[0,0],dat[0,c]),xytext=(tx,ty),color=clr,fontweight='bold')) + self.lpatch.append(mpatches.Patch(color=clr, label=fn.split(os.path.sep)[-1].split('.txt')[0])) + ddx+=1 ax.set_ylim(yl) @@ -404,8 +411,9 @@ def clearlextdatobj (self): except: o[0].set_visible(False) del self.lextdatobj - self.lextdatobj = [] - self.lpatch = [] + self.lextdatobj = [] # reset list of external data objects + self.lpatch = [] # reset legend + self.clridx = 5 # reset index for next color for drawing external data if self.hassimdata(): self.lpatch.append(mpatches.Patch(color='black', label='Simulation')) if hasattr(self,'annot_avg'): self.annot_avg.set_visible(False)