From 780fba24c41a9261d6df8a76a2dc2d3d3428b78c Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 2 Nov 2018 11:01:31 +0100 Subject: [PATCH] [figures] make py3 compatible --- bootstrap/lecture/bootstrapsem.py | 4 ++-- bootstrap/lecture/permutecorrelation.py | 2 +- likelihood/lecture/mlemean.py | 2 +- pointprocesses/lecture/firingrates.py | 2 +- pointprocesses/lecture/isihexamples.py | 6 +++--- pointprocesses/lecture/rasterexamples.py | 4 ++-- pointprocesses/lecture/returnmapexamples.py | 6 +++--- pointprocesses/lecture/serialcorrexamples.py | 6 +++--- pointprocesses/lecture/sta.py | 2 +- statistics/lecture/displayunivariatedata.py | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bootstrap/lecture/bootstrapsem.py b/bootstrap/lecture/bootstrapsem.py index 347f40f..66154ce 100644 --- a/bootstrap/lecture/bootstrapsem.py +++ b/bootstrap/lecture/bootstrapsem.py @@ -15,13 +15,13 @@ x = rng.randn(nsamples) # bootstrap the mean: mus = [] -for i in xrange(nresamples) : +for i in range(nresamples) : mus.append(np.mean(x[rng.randint(0, nsamples, nsamples)])) hmus, _ = np.histogram(mus, bins, density=True) # many SRS: musrs = [] -for i in xrange(nresamples) : +for i in range(nresamples) : musrs.append(np.mean(rng.randn(nsamples))) hmusrs, _ = np.histogram(musrs, bins, density=True) diff --git a/bootstrap/lecture/permutecorrelation.py b/bootstrap/lecture/permutecorrelation.py index ab1a583..9b4d4f8 100644 --- a/bootstrap/lecture/permutecorrelation.py +++ b/bootstrap/lecture/permutecorrelation.py @@ -19,7 +19,7 @@ rd = np.corrcoef(x, y)[0, 1] # permutation: nperm = 1000 rs = [] -for i in xrange(nperm) : +for i in np.arange(nperm) : xr=rng.permutation(x) yr=rng.permutation(y) rs.append( np.corrcoef(xr, yr)[0, 1] ) diff --git a/likelihood/lecture/mlemean.py b/likelihood/lecture/mlemean.py index 892e663..f0b6506 100644 --- a/likelihood/lecture/mlemean.py +++ b/likelihood/lecture/mlemean.py @@ -41,7 +41,7 @@ for mu in mus : ax.text(mu-0.1, 0.04, '?', zorder=1, ha='right') else : ax.text(mu+0.1, 0.04, '?', zorder=1) -for k in xrange(len(mus)) : +for k in np.arange(len(mus)) : ax.plot(x, g[:,k], zorder=5) ax.scatter(xd, 0.05*rng.rand(len(xd))+0.2, s=30, zorder=10) diff --git a/pointprocesses/lecture/firingrates.py b/pointprocesses/lecture/firingrates.py index 6b98732..d6d1666 100644 --- a/pointprocesses/lecture/firingrates.py +++ b/pointprocesses/lecture/firingrates.py @@ -86,7 +86,7 @@ def plot_isi_rate(spike_times, max_t=30, dt=1e-4): def get_binned_rate(times, bin_width=0.05, max_t=30., dt=1e-4): time = np.arange(0., max_t, dt) bins = np.arange(0., max_t, bin_width) - bin_indices = bins / dt + bin_indices = np.asarray(bins / dt, np.int) hist, _ = sp.histogram(times, bins) rate = np.zeros(time.shape) diff --git a/pointprocesses/lecture/isihexamples.py b/pointprocesses/lecture/isihexamples.py index b03d2a9..74a4b88 100644 --- a/pointprocesses/lecture/isihexamples.py +++ b/pointprocesses/lecture/isihexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in np.arange(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -41,7 +41,7 @@ def pifspikes(input, trials, dt, D=0.1) : def isis( spikes ) : isi = [] - for k in xrange(len(spikes)) : + for k in np.arange(len(spikes)) : isi.extend(np.diff(spikes[k])) return isi @@ -76,7 +76,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in np.arange(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/rasterexamples.py b/pointprocesses/lecture/rasterexamples.py index 9c66897..042bda2 100644 --- a/pointprocesses/lecture/rasterexamples.py +++ b/pointprocesses/lecture/rasterexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in range(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -55,7 +55,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/returnmapexamples.py b/pointprocesses/lecture/returnmapexamples.py index 96803ff..829cf6d 100644 --- a/pointprocesses/lecture/returnmapexamples.py +++ b/pointprocesses/lecture/returnmapexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in range(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -41,7 +41,7 @@ def pifspikes(input, trials, dt, D=0.1) : def isis( spikes ) : isi = [] - for k in xrange(len(spikes)) : + for k in range(len(spikes)) : isi.extend(np.diff(spikes[k])) return np.array( isi ) @@ -84,7 +84,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/serialcorrexamples.py b/pointprocesses/lecture/serialcorrexamples.py index e7fff9c..a2dc853 100644 --- a/pointprocesses/lecture/serialcorrexamples.py +++ b/pointprocesses/lecture/serialcorrexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in range(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -41,7 +41,7 @@ def pifspikes(input, trials, dt, D=0.1) : def isis( spikes ) : isi = [] - for k in xrange(len(spikes)) : + for k in range(len(spikes)) : isi.extend(np.diff(spikes[k])) return np.array( isi ) @@ -95,7 +95,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/sta.py b/pointprocesses/lecture/sta.py index c5d702b..127c5ae 100644 --- a/pointprocesses/lecture/sta.py +++ b/pointprocesses/lecture/sta.py @@ -6,7 +6,7 @@ from IPython import embed def plot_sta(times, stim, dt, t_min=-0.1, t_max=.1): count = 0 - sta = np.zeros((abs(t_min) + abs(t_max))/dt) + sta = np.zeros(int((abs(t_min) + abs(t_max))/dt)) time = np.arange(t_min, t_max, dt) if len(stim.shape) > 1 and stim.shape[1] > 1: stim = stim[:,1] diff --git a/statistics/lecture/displayunivariatedata.py b/statistics/lecture/displayunivariatedata.py index 546d4ff..55130a8 100644 --- a/statistics/lecture/displayunivariatedata.py +++ b/statistics/lecture/displayunivariatedata.py @@ -53,7 +53,7 @@ ax.annotate('mean plus\nstd. dev.', arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0), connectionstyle="angle3,angleA=-60,angleB=80") ) -ax = fig.add_axes([xpos, ypos, width, height], axis_bgcolor='none') +ax = fig.add_axes([xpos, ypos, width, height]) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['left'].set_visible(False) @@ -92,7 +92,7 @@ ax.annotate('median', arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0), connectionstyle="angle3,angleA=-60,angleB=20") ) -ax = fig.add_axes([xpos+width+0.03, ypos, 0.98-(xpos+width+0.03), height], axis_bgcolor='none') +ax = fig.add_axes([xpos+width+0.03, ypos, 0.98-(xpos+width+0.03), height]) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.xaxis.set_ticks_position('bottom')