Skip to content

Commit ceb4448

Browse files
author
Dilawar Singh
committed
Fixes to python2 related failure.
1 parent 5a49966 commit ceb4448

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_script:
99
- sleep 3 # give xvfb some time to start
1010
- # this require latest moose.
1111
- sudo apt-get update
12-
- sudo apt-get install python-scipy python-networkx python-tk python-matplotlib -qq
12+
- sudo apt-get install graphviz python-networkx python-tk -qq
1313

1414
script:
1515
- cp ./.travis/matplotlibrc .

findSim.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'''
3636
from __future__ import print_function
3737
import heapq
38-
import pylab
38+
import matplotlib.pyplot as plt
3939
import numpy as np
4040
import sys
4141
import argparse
@@ -280,7 +280,11 @@ def displayPlots( self, fname, modelLookup, stim, hideSubplots, exptType ):
280280
elms = modelLookup[i]
281281
for j in elms:
282282
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))
284288
elif "barchart" in exptType:
285289
for i in self.entities:
286290
elms = modelLookup[i]
@@ -320,17 +324,17 @@ def displayPlots( self, fname, modelLookup, stim, hideSubplots, exptType ):
320324
sumvec += ypts
321325
if (not hideSubplots) and (len( elms ) > 1):
322326
# Plot summed components
323-
pylab.plot( xpts, ypts, 'r:', label = j.name )
327+
plt.plot( xpts, ypts, 'r:', label = j.name )
324328

325-
pylab.plot( xpts, sumvec, 'r--' )
329+
plt.plot( xpts, sumvec, 'r--' )
326330
ylabel = pp.ylabel
327331
if self.field in ( epspFields + epscFields ):
328332
if self.field in ( epspFields ):
329-
pylab.ylabel( '{} Vm ({})'.format( self.entities[0], tsUnits ) )
333+
plt.ylabel( '{} Vm ({})'.format( self.entities[0], tsUnits ) )
330334
else:
331-
pylab.ylabel( '{} holding current ({})'.format( self.entities[0], tsUnits ) )
335+
plt.ylabel( '{} holding current ({})'.format( self.entities[0], tsUnits ) )
332336

333-
pylab.figure(2)
337+
plt.figure(2)
334338
if self.useNormalization:
335339
ylabel = '{} Fold change'.format( self.field )
336340
pp.plotme( fname, ylabel )
@@ -1249,39 +1253,39 @@ def convertBarChartLabels( self, readout, stim ):
12491253
def plotbar( self, readout, stim, scriptName ):
12501254
barpos = np.arange( len( self.sim ) )
12511255
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")
12581262
ticklabels = [ i[0] + '\n' for i in readout.data ]
12591263
assert len( ticklabels ) == len( barpos )
12601264
ticklabels = self.convertBarChartLabels( readout, stim )
1261-
pylab.xticks(barpos, ticklabels )
1265+
plt.xticks(barpos, ticklabels )
12621266

12631267
def plotme( self, scriptName, ylabel, joinSimPoints = False ):
12641268
sp = 'ro-' if joinSimPoints else 'ro'
12651269
if self.useXlog:
12661270
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' )
12691273
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' )
12721276
else:
12731277
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' )
12761280
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' )
12801284

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")
12851289

12861290
########################################################################
12871291
def loadTsv( fname ):
@@ -1590,10 +1594,10 @@ def innerMain( script, modelFile = "model/synSynth7.g", dumpFname = "", paramFna
15901594
if not hidePlot:
15911595
print( "Score = {:.3f} for\t{}\tElapsed Time = {:.1f} s".format( score, os.path.basename(script), elapsedTime ) )
15921596
for i in readouts:
1593-
pylab.figure(1)
1597+
plt.figure(1)
15941598
i.displayPlots( script, model.modelLookup, stims[0], hideSubplots, expt.exptType )
15951599

1596-
pylab.show()
1600+
plt.show()
15971601
moose.delete( modelId )
15981602
if moose.exists( '/library' ):
15991603
moose.delete( '/library' )

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ PYTHON=$(which python)
88
# From here https://stackoverflow.com/a/40950971/1805129
99
PYTHON_VERSION=$(python -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/')
1010
if [ "$PYTHON_VERSION" -eq "27" ]; then
11-
$PYTHON -m pip uninstall matplotlib -y || echo "Failed to remove matplotlib"
11+
# $PYTHON -m pip uninstall matplotlib -y || echo "Failed to remove matplotlib"
1212
$PYTHON -m pip install matplotlib==2.2.3 --upgrade
1313
$PYTHON -m pip install scipy==1.1.0 --upgrade
1414
else
15-
$PYTHON -m pip uninstall matplotlib -y || echo "Failed to remove matplotlib"
15+
# $PYTHON -m pip uninstall matplotlib -y || echo "Failed to remove matplotlib"
1616
$PYTHON -m pip install matplotlib --upgrade
1717
$PYTHON -m pip install --upgrade
1818
fi

0 commit comments

Comments
 (0)