[deprecations] replace scipy.hist with np function ...
and deprecation of normed keyword in nphistogram
This commit is contained in:
parent
5be1c25187
commit
8ab483d3a8
@ -11,7 +11,7 @@ def get_instantaneous_rate(times, max_t=30., dt=1e-4):
|
|||||||
indices = np.asarray(times / dt, dtype=int)
|
indices = np.asarray(times / dt, dtype=int)
|
||||||
intervals = np.diff(np.hstack(([0], times)))
|
intervals = np.diff(np.hstack(([0], times)))
|
||||||
inst_rate = np.zeros(time.shape)
|
inst_rate = np.zeros(time.shape)
|
||||||
|
|
||||||
for i, index in enumerate(indices[1:]):
|
for i, index in enumerate(indices[1:]):
|
||||||
inst_rate[indices[i-1]:indices[i]] = 1/intervals[i]
|
inst_rate[indices[i-1]:indices[i]] = 1/intervals[i]
|
||||||
return time, inst_rate
|
return time, inst_rate
|
||||||
@ -20,16 +20,16 @@ def get_instantaneous_rate(times, max_t=30., dt=1e-4):
|
|||||||
def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
|
def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
|
||||||
times = np.squeeze(spike_times[0][0])[:50000]
|
times = np.squeeze(spike_times[0][0])[:50000]
|
||||||
time, rate = get_instantaneous_rate(times, max_t=50000*dt)
|
time, rate = get_instantaneous_rate(times, max_t=50000*dt)
|
||||||
|
|
||||||
rates = np.zeros((len(rate), len(spike_times)))
|
rates = np.zeros((len(rate), len(spike_times)))
|
||||||
for i in range(len(spike_times)):
|
for i in range(len(spike_times)):
|
||||||
_, rates[:, i] = get_instantaneous_rate(np.squeeze(spike_times[i][0])[:50000],
|
_, rates[:, i] = get_instantaneous_rate(np.squeeze(spike_times[i][0])[:50000],
|
||||||
max_t=50000*dt)
|
max_t=50000*dt)
|
||||||
avg_rate = np.mean(rates, axis=1)
|
avg_rate = np.mean(rates, axis=1)
|
||||||
rate_std = np.std(rates, axis=1)
|
rate_std = np.std(rates, axis=1)
|
||||||
|
|
||||||
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=cm_size(figure_width, 1.2*figure_height))
|
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=cm_size(figure_width, 1.2*figure_height))
|
||||||
|
|
||||||
ax1.vlines(times[times < (50000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
ax1.vlines(times[times < (50000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
||||||
ax1.set_ylabel('Spikes')
|
ax1.set_ylabel('Spikes')
|
||||||
ax1.set_xlim(0, 5)
|
ax1.set_xlim(0, 5)
|
||||||
@ -43,7 +43,7 @@ def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
|
|||||||
ax3.set_ylabel('Firing rate', 'Hz')
|
ax3.set_ylabel('Firing rate', 'Hz')
|
||||||
ax3.legend()
|
ax3.legend()
|
||||||
ax3.set_ylim(0, 450)
|
ax3.set_ylim(0, 450)
|
||||||
|
|
||||||
fig.savefig("isimethod.pdf")
|
fig.savefig("isimethod.pdf")
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
@ -52,9 +52,9 @@ def get_binned_rate(times, bin_width=0.05, max_t=30., dt=1e-4):
|
|||||||
time = np.arange(0., max_t, dt)
|
time = np.arange(0., max_t, dt)
|
||||||
bins = np.arange(0., max_t, bin_width)
|
bins = np.arange(0., max_t, bin_width)
|
||||||
bin_indices = np.asarray(bins / dt, np.int)
|
bin_indices = np.asarray(bins / dt, np.int)
|
||||||
hist, _ = sp.histogram(times, bins)
|
hist, _ = np.histogram(times, bins)
|
||||||
rate = np.zeros(time.shape)
|
rate = np.zeros(time.shape)
|
||||||
|
|
||||||
for i, b in enumerate(bin_indices[1:]):
|
for i, b in enumerate(bin_indices[1:]):
|
||||||
rate[bin_indices[i-1]:b] = hist[i-1]/bin_width
|
rate[bin_indices[i-1]:b] = hist[i-1]/bin_width
|
||||||
return time, rate
|
return time, rate
|
||||||
@ -68,7 +68,7 @@ def plot_bin_rate(spike_times, bin_width, max_t=30, dt=1e-4):
|
|||||||
_, rates[:, i] = get_binned_rate(np.squeeze(spike_times[i][0]))
|
_, rates[:, i] = get_binned_rate(np.squeeze(spike_times[i][0]))
|
||||||
avg_rate = np.mean(rates, axis=1)
|
avg_rate = np.mean(rates, axis=1)
|
||||||
rate_std = np.std(rates, axis=1)
|
rate_std = np.std(rates, axis=1)
|
||||||
|
|
||||||
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=cm_size(figure_width, 1.2*figure_height))
|
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=cm_size(figure_width, 1.2*figure_height))
|
||||||
|
|
||||||
ax1.vlines(times[times < (100000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
ax1.vlines(times[times < (100000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
||||||
|
@ -2,10 +2,11 @@ import numpy as np
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from plotstyle import *
|
from plotstyle import *
|
||||||
|
|
||||||
|
sketch_style()
|
||||||
# roll the die:
|
# roll the die:
|
||||||
rng = np.random.RandomState(57281)
|
rng = np.random.RandomState(57281)
|
||||||
x1 = rng.random_integers(1, 6, 100)
|
x1 = rng.randint(1, 7, 100)
|
||||||
x2 = rng.random_integers(1, 6, 500)
|
x2 = rng.randint(1, 7, 500)
|
||||||
bins = np.arange(0.5, 7, 1.0)
|
bins = np.arange(0.5, 7, 1.0)
|
||||||
|
|
||||||
fig, (ax1, ax2) = plt.subplots(1, 2)
|
fig, (ax1, ax2) = plt.subplots(1, 2)
|
||||||
@ -26,5 +27,6 @@ ax2.set_xlabel('x')
|
|||||||
ax2.set_ylim(0, 0.23)
|
ax2.set_ylim(0, 0.23)
|
||||||
ax2.set_ylabel('Probability')
|
ax2.set_ylabel('Probability')
|
||||||
ax2.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], zorder=-10, **lsAm)
|
ax2.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], zorder=-10, **lsAm)
|
||||||
ax2.hist([x2, x1], bins, normed=True, zorder=-5, **fs)
|
ax2.hist([x2, x1], bins, density=True, zorder=-5, **fs)
|
||||||
|
fig.subplots_adjust(left=0.125)
|
||||||
fig.savefig('diehistograms.pdf')
|
fig.savefig('diehistograms.pdf')
|
||||||
|
@ -4,6 +4,7 @@ import matplotlib.gridspec as gridspec
|
|||||||
from scipy.stats import gaussian_kde
|
from scipy.stats import gaussian_kde
|
||||||
from plotstyle import *
|
from plotstyle import *
|
||||||
|
|
||||||
|
sketch_style()
|
||||||
#rng = np.random.RandomState(981)
|
#rng = np.random.RandomState(981)
|
||||||
#data = rng.randn(40, 1) + 4.0
|
#data = rng.randn(40, 1) + 4.0
|
||||||
rng = np.random.RandomState(1981)
|
rng = np.random.RandomState(1981)
|
||||||
@ -90,6 +91,6 @@ bw = 0.75
|
|||||||
bins = np.arange(0, 8.0+bw, bw)
|
bins = np.arange(0, 8.0+bw, bw)
|
||||||
h, b = np.histogram(data, bins)
|
h, b = np.histogram(data, bins)
|
||||||
ax.barh(b[:-1], h/bw/np.sum(h), bw, **fsB)
|
ax.barh(b[:-1], h/bw/np.sum(h), bw, **fsB)
|
||||||
|
fig.subplots_adjust(top=0.9, bottom=0.2)
|
||||||
plt.savefig('displayunivariatedata.pdf')
|
plt.savefig('displayunivariatedata.pdf')
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ ax.set_ylabel('p(x)')
|
|||||||
ax.set_ylim(0.0, 0.49)
|
ax.set_ylim(0.0, 0.49)
|
||||||
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
||||||
ax.hist(r, np.arange(-4.1, 4, 0.4), normed=True, zorder=-5, **fsC)
|
ax.hist(r, np.arange(-4.1, 4, 0.4), density=True, zorder=-5, **fsC)
|
||||||
|
|
||||||
ax = fig.add_subplot(spec[1, 0])
|
ax = fig.add_subplot(spec[1, 0])
|
||||||
ax.set_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
@ -54,7 +54,7 @@ ax.set_ylabel('p(x)')
|
|||||||
ax.set_ylim(0.0, 0.49)
|
ax.set_ylim(0.0, 0.49)
|
||||||
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
||||||
ax.hist(r, np.arange(-4.3, 4, 0.4), normed=True, zorder=-5, **fsC)
|
ax.hist(r, np.arange(-4.3, 4, 0.4), density=True, zorder=-5, **fsC)
|
||||||
|
|
||||||
ax = fig.add_subplot(spec[:, 1])
|
ax = fig.add_subplot(spec[:, 1])
|
||||||
ax.set_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
@ -66,6 +66,6 @@ ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
|||||||
kd, xx = kerneldensity(r, -3.2, 3.2, 0.2)
|
kd, xx = kerneldensity(r, -3.2, 3.2, 0.2)
|
||||||
ax.fill_between(xx, 0.0, kd, zorder=-5, **fsDs)
|
ax.fill_between(xx, 0.0, kd, zorder=-5, **fsDs)
|
||||||
ax.plot(xx, kd, '-', zorder=-1, **lsB)
|
ax.plot(xx, kd, '-', zorder=-1, **lsB)
|
||||||
|
fig.subplots_adjust(left=0.15)
|
||||||
fig.savefig('kerneldensity.pdf')
|
fig.savefig('kerneldensity.pdf')
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ ax2.set_ylabel('Probab. density p(x)')
|
|||||||
ax2.set_ylim(0.0, 0.44)
|
ax2.set_ylim(0.0, 0.44)
|
||||||
ax2.set_yticks(np.arange(0.0, 0.41, 0.1))
|
ax2.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
ax2.plot(x, g, zorder=-1, **lsA)
|
ax2.plot(x, g, zorder=-1, **lsA)
|
||||||
ax2.hist(r, 5, normed=True, zorder=-10, **fsB)
|
ax2.hist(r, 5, density=True, zorder=-10, **fsB)
|
||||||
ax2.hist(r, 20, normed=True, zorder=-5, **fsC)
|
ax2.hist(r, 20, density=True, zorder=-5, **fsC)
|
||||||
|
|
||||||
fig.savefig('pdfhistogram.pdf')
|
fig.savefig('pdfhistogram.pdf')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user