|
35 | 35 | ''' |
36 | 36 | from __future__ import print_function |
37 | 37 | import heapq |
38 | | -import pylab |
| 38 | +import matplotlib.pyplot as plt |
39 | 39 | import numpy as np |
40 | 40 | import sys |
41 | 41 | import argparse |
@@ -280,7 +280,11 @@ def displayPlots( self, fname, modelLookup, stim, hideSubplots, exptType ): |
280 | 280 | elms = modelLookup[i] |
281 | 281 | for j in elms: |
282 | 282 | pp = PlotPanel( self, exptType, xlabel = j.name +'('+stim.quantityUnits+')' ) |
283 | | - pp.plotme( fname, pp.ylabel, joinSimPoints = True ) |
| 283 | + try: |
| 284 | + pp.plotme( fname, pp.ylabel, joinSimPoints = True ) |
| 285 | + except Exception as e: |
| 286 | + print('Warning: displayPlot: Failed to plot ' |
| 287 | + '%s due to "%s"' % (fname,e)) |
284 | 288 | elif "barchart" in exptType: |
285 | 289 | for i in self.entities: |
286 | 290 | elms = modelLookup[i] |
@@ -320,17 +324,17 @@ def displayPlots( self, fname, modelLookup, stim, hideSubplots, exptType ): |
320 | 324 | sumvec += ypts |
321 | 325 | if (not hideSubplots) and (len( elms ) > 1): |
322 | 326 | # Plot summed components |
323 | | - pylab.plot( xpts, ypts, 'r:', label = j.name ) |
| 327 | + plt.plot( xpts, ypts, 'r:', label = j.name ) |
324 | 328 |
|
325 | | - pylab.plot( xpts, sumvec, 'r--' ) |
| 329 | + plt.plot( xpts, sumvec, 'r--' ) |
326 | 330 | ylabel = pp.ylabel |
327 | 331 | if self.field in ( epspFields + epscFields ): |
328 | 332 | if self.field in ( epspFields ): |
329 | | - pylab.ylabel( '{} Vm ({})'.format( self.entities[0], tsUnits ) ) |
| 333 | + plt.ylabel( '{} Vm ({})'.format( self.entities[0], tsUnits ) ) |
330 | 334 | else: |
331 | | - pylab.ylabel( '{} holding current ({})'.format( self.entities[0], tsUnits ) ) |
| 335 | + plt.ylabel( '{} holding current ({})'.format( self.entities[0], tsUnits ) ) |
332 | 336 |
|
333 | | - pylab.figure(2) |
| 337 | + plt.figure(2) |
334 | 338 | if self.useNormalization: |
335 | 339 | ylabel = '{} Fold change'.format( self.field ) |
336 | 340 | pp.plotme( fname, ylabel ) |
@@ -1249,39 +1253,39 @@ def convertBarChartLabels( self, readout, stim ): |
1249 | 1253 | def plotbar( self, readout, stim, scriptName ): |
1250 | 1254 | barpos = np.arange( len( self.sim ) ) |
1251 | 1255 | width = 0.35 # A reasonable looking bar width |
1252 | | - exptBar = pylab.bar(barpos - width/2, self.expt, width, yerr=self.yerror, color='SkyBlue', label='Experiment') |
1253 | | - simBar = pylab.bar(barpos + width/2, self.sim, width, color='IndianRed', label='Simulation') |
1254 | | - pylab.xlabel( "Stimulus combinations" ) |
1255 | | - pylab.ylabel( self.ylabel ) |
1256 | | - pylab.title(scriptName) |
1257 | | - pylab.legend(fontsize="small",loc="upper left") |
| 1256 | + exptBar = plt.bar(barpos - width/2, self.expt, width, yerr=self.yerror, color='SkyBlue', label='Experiment') |
| 1257 | + simBar = plt.bar(barpos + width/2, self.sim, width, color='IndianRed', label='Simulation') |
| 1258 | + plt.xlabel( "Stimulus combinations" ) |
| 1259 | + plt.ylabel( self.ylabel ) |
| 1260 | + plt.title(scriptName) |
| 1261 | + plt.legend(fontsize="small",loc="upper left") |
1258 | 1262 | ticklabels = [ i[0] + '\n' for i in readout.data ] |
1259 | 1263 | assert len( ticklabels ) == len( barpos ) |
1260 | 1264 | ticklabels = self.convertBarChartLabels( readout, stim ) |
1261 | | - pylab.xticks(barpos, ticklabels ) |
| 1265 | + plt.xticks(barpos, ticklabels ) |
1262 | 1266 |
|
1263 | 1267 | def plotme( self, scriptName, ylabel, joinSimPoints = False ): |
1264 | 1268 | sp = 'ro-' if joinSimPoints else 'ro' |
1265 | 1269 | if self.useXlog: |
1266 | 1270 | if self.useYlog: |
1267 | | - pylab.loglog( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' ) |
1268 | | - pylab.loglog( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
| 1271 | + plt.loglog( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' ) |
| 1272 | + plt.loglog( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
1269 | 1273 | else: |
1270 | | - pylab.semilogx( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' ) |
1271 | | - pylab.semilogx( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
| 1274 | + plt.semilogx( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' ) |
| 1275 | + plt.semilogx( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
1272 | 1276 | else: |
1273 | 1277 | if self.useYlog: |
1274 | | - pylab.semilogy( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' ) |
1275 | | - pylab.semilogy( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
| 1278 | + plt.semilogy( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' ) |
| 1279 | + plt.semilogy( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
1276 | 1280 | else: |
1277 | | - pylab.plot( self.xpts, self.expt,'bo-', label = 'experiment', linewidth='2' ) |
1278 | | - pylab.errorbar( self.xpts, self.expt, yerr=self.yerror ) |
1279 | | - pylab.plot( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
| 1281 | + plt.plot( self.xpts, self.expt,'bo-', label = 'experiment', linewidth='2' ) |
| 1282 | + plt.errorbar( self.xpts, self.expt, yerr=self.yerror ) |
| 1283 | + plt.plot( self.xpts, self.sim, sp, label = 'sim', linewidth='2' ) |
1280 | 1284 |
|
1281 | | - pylab.xlabel( self.xlabel ) |
1282 | | - pylab.ylabel( ylabel ) |
1283 | | - pylab.title(scriptName) |
1284 | | - pylab.legend(fontsize="small",loc="lower right") |
| 1285 | + plt.xlabel( self.xlabel ) |
| 1286 | + plt.ylabel( ylabel ) |
| 1287 | + plt.title(scriptName) |
| 1288 | + plt.legend(fontsize="small",loc="lower right") |
1285 | 1289 |
|
1286 | 1290 | ######################################################################## |
1287 | 1291 | def loadTsv( fname ): |
@@ -1590,10 +1594,10 @@ def innerMain( script, modelFile = "model/synSynth7.g", dumpFname = "", paramFna |
1590 | 1594 | if not hidePlot: |
1591 | 1595 | print( "Score = {:.3f} for\t{}\tElapsed Time = {:.1f} s".format( score, os.path.basename(script), elapsedTime ) ) |
1592 | 1596 | for i in readouts: |
1593 | | - pylab.figure(1) |
| 1597 | + plt.figure(1) |
1594 | 1598 | i.displayPlots( script, model.modelLookup, stims[0], hideSubplots, expt.exptType ) |
1595 | 1599 |
|
1596 | | - pylab.show() |
| 1600 | + plt.show() |
1597 | 1601 | moose.delete( modelId ) |
1598 | 1602 | if moose.exists( '/library' ): |
1599 | 1603 | moose.delete( '/library' ) |
|
0 commit comments