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