-
Notifications
You must be signed in to change notification settings - Fork 1
/
r2star_modelInspector.py
47 lines (41 loc) · 1.65 KB
/
r2star_modelInspector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
def signal(A, TE, R2Star):
return A * np.exp(-1*TE*R2Star)
axis_color = 'lightgoldenrodyellow'
fig = plt.figure()
# Draw the plot
ax = fig.add_subplot(111)
fig.subplots_adjust(left=0.25, bottom=0.25)
TEs = np.arange(0.0, 5.0, 0.001)
A= 5000
R = 0.5
[line] = ax.plot(TEs, signal(A, TEs, R), linewidth=2, color='red')
ax.set_xlim([0, 5])
ax.set_ylim([0, 200])
# Add two sliders for tweaking the parameters
amp_slider_ax = fig.add_axes([0.25, 0.15, 0.65, 0.03], axisbg=axis_color)
amp_slider = Slider(amp_slider_ax, 'A', 0.1, 200., valinit=A)
freq_slider_ax = fig.add_axes([0.25, 0.1, 0.65, 0.03], axisbg=axis_color)
freq_slider = Slider(freq_slider_ax, 'R2Star', 0.1, 6., valinit=R)
def sliders_on_changed(val):
line.set_ydata(signal(amp_slider.val, TEs, freq_slider.val))
fig.canvas.draw_idle()
amp_slider.on_changed(sliders_on_changed)
freq_slider.on_changed(sliders_on_changed)
# Add a button for resetting the parameters
reset_button_ax = fig.add_axes([0.8, 0.025, 0.1, 0.04])
reset_button = Button(reset_button_ax, 'Reset', color=axis_color, hovercolor='0.975')
def reset_button_on_clicked(mouse_event):
freq_slider.reset()
amp_slider.reset()
reset_button.on_clicked(reset_button_on_clicked)
# Add a set of radio buttons for changing color
color_radios_ax = fig.add_axes([0.025, 0.5, 0.15, 0.15], axisbg=axis_color)
color_radios = RadioButtons(color_radios_ax, ('red', 'blue', 'green'), active=0)
def color_radios_on_clicked(label):
line.set_color(label)
fig.canvas.draw_idle()
color_radios.on_clicked(color_radios_on_clicked)
plt.show()