Skip to content

Commit f0a8ced

Browse files
committed
DOC: update plots to new interfaces
Update to changes in use of symbolic HRFs. Turn of 'usetex' for matplotlib; matplotlib handles the TeX in the plots fine with its own renderer. Add comments and change imports to more canonical form.
1 parent f2c0fba commit f0a8ced

File tree

4 files changed

+57
-45
lines changed

4 files changed

+57
-45
lines changed

doc/users/plots/event_amplitude.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
33
import numpy as np
44
import pylab
55

6-
from nipy.modalities.fmri.utils import events, Symbol, Vectorize
7-
from nipy.modalities.fmri.hrf import glover_sympy
6+
from nipy.modalities.fmri.utils import events, Symbol, lambdify_t
7+
from nipy.modalities.fmri.hrf import glover
88

9+
# Symbol for amplitude
910
a = Symbol('a')
10-
b = np.linspace(0,50,6)
11-
ba = b*([-1,1]*3)
12-
d = events(b, amplitudes=ba, g=a+0.5*a**2, f=glover_sympy)
13-
dt = Vectorize(d)
14-
tt = np.linspace(0,60,601)
15-
16-
pylab.plot(tt, dt(tt), c='r')
17-
for bb, aa in zip(b,ba):
18-
pylab.plot([bb,bb],[0,25*aa], c='b')
11+
12+
# Some event onsets regularly spaced
13+
onsets = np.linspace(0,50,6)
14+
15+
# Make amplitudes from onset times (greater as function of time)
16+
amplitudes = onsets[:]
17+
18+
# Flip even numbered amplitudes
19+
amplitudes = amplitudes * ([-1, 1] * 3)
20+
21+
# Make event functions
22+
evs = events(onsets, amplitudes=amplitudes, g=a + 0.5 * a**2, f=glover)
23+
24+
# Real valued function for symbolic events
25+
real_evs = lambdify_t(evs)
26+
27+
# Time points at which to sample
28+
t_samples = np.linspace(0,60,601)
29+
30+
pylab.plot(t_samples, real_evs(t_samples), c='r')
31+
for onset, amplitude in zip(onsets, amplitudes):
32+
pylab.plot([onset, onset],[0, 25 * amplitude], c='b')
1933

2034
pylab.show()

doc/users/plots/hrf.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66

77
import numpy as np
88

9-
from nipy.modalities.fmri import hrf
9+
from nipy.modalities.fmri import hrf, utils
1010

11-
import pylab
11+
import matplotlib.pyplot as plt
1212

13-
14-
from matplotlib import rc
15-
rc('text', usetex=True)
13+
# hrf.glover is a symbolic function; get a function of time to work on arrays
14+
hrf_func = utils.lambdify_t(hrf.glover(utils.T))
1615

1716
t = np.linspace(0,25,200)
18-
pylab.plot(t, hrf.glover(t))
19-
a=pylab.gca()
17+
plt.plot(t, hrf_func(t))
18+
a=plt.gca()
2019
a.set_xlabel(r'$t$')
2120
a.set_ylabel(r'$h_{can}(t)$')
22-
23-

doc/users/plots/hrf_delta.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
of delta functions times coefficient values
66
"""
77

8-
import pylab
9-
from matplotlib import rc
10-
rc('text', usetex=True)
8+
import matplotlib.pyplot as plt
119

10+
# Coefficients for a and b
1211
ba = 1
1312
bb = -2
1413

15-
ta = [0,4,8,12,16]; tb = [2,6,10,14,18]
14+
# Times for a and b
15+
ta = [0,4,8,12,16]
16+
tb = [2,6,10,14,18]
1617

1718
for t in ta:
18-
pylab.plot([t,t],[0,ba],c='r')
19+
plt.plot([t,t],[0,ba],c='r')
1920
for t in tb:
20-
pylab.plot([t,t],[0,bb],c='b')
21+
plt.plot([t,t],[0,bb],c='b')
2122

22-
a = pylab.gca()
23+
a = plt.gca()
2324
a.set_xlabel(r'$t$')
2425
a.set_ylabel(r'$n(t)$')
25-

doc/users/plots/hrf_different.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,34 @@
66

77
import numpy as np
88

9-
import pylab
10-
11-
from sympy import lambdify
9+
import matplotlib.pyplot as plt
1210

1311
from nipy.modalities.fmri import hrf
12+
from nipy.modalities.fmri.utils import T, lambdify_t
13+
1414

15-
glover = hrf.glover_sympy
16-
afni = hrf.afni_sympy
15+
# HRFs as functions of (symbolic) time
16+
glover = hrf.glover(T)
17+
afni = hrf.afni(T)
1718

1819
ta = [0,4,8,12,16]; tb = [2,6,10,14,18]
1920
ba = 1; bb = -2
20-
na = ba * sum([glover.subs(hrf.t, hrf.t - t) for t in ta])
21-
nb = bb * sum([afni.subs(hrf.t, hrf.t - t) for t in tb])
21+
na = ba * sum([glover.subs(T, T - t) for t in ta])
22+
nb = bb * sum([afni.subs(T, T - t) for t in tb])
2223

23-
nav = lambdify(hrf.vector_t, na.subs(hrf.t, hrf.vector_t), 'numpy')
24-
nbv = lambdify(hrf.vector_t, nb.subs(hrf.t, hrf.vector_t), 'numpy')
24+
nav = lambdify_t(na)
25+
nbv = lambdify_t(nb)
2526

2627
t = np.linspace(0,30,200)
27-
pylab.plot(t, nav(t), c='r', label='Face')
28-
pylab.plot(t, nbv(t), c='b', label='Object')
29-
pylab.plot(t, nbv(t)+nav(t), c='g', label='Neuronal')
28+
plt.plot(t, nav(t), c='r', label='Face')
29+
plt.plot(t, nbv(t), c='b', label='Object')
30+
plt.plot(t, nbv(t)+nav(t), c='g', label='Combined')
3031

3132
for t in ta:
32-
pylab.plot([t,t],[0,ba*0.5],c='r')
33+
plt.plot([t,t],[0,ba*0.5],c='r')
3334
for t in tb:
34-
pylab.plot([t,t],[0,bb*0.5],c='b')
35-
pylab.plot([0,30], [0,0],c='#000000')
36-
pylab.legend()
35+
plt.plot([t,t],[0,bb*0.5],c='b')
36+
plt.plot([0,30], [0,0],c='#000000')
37+
plt.legend()
3738

38-
pylab.show()
39+
plt.show()

0 commit comments

Comments
 (0)