Skip to content

Commit 1f6f868

Browse files
committed
feat: allow selecting what plots to show
Fixes #59
1 parent 4432301 commit 1f6f868

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
8282
self.current_plot = current_plot
8383
self.memb_pot_plot = memb_pot_plot
8484

85+
self.num_plots = (int(self.injected_current_plot) +
86+
int(self.gating_plot) + int(self.cond_dens_plot) +
87+
int(self.current_plot) + int(self.memb_pot_plot))
88+
89+
self.plot_count = 0
90+
8591
def alpha_m(self, V):
8692
"""Channel gating kinetics. Functions of membrane voltage"""
8793
return 0.1*(V+40.0)/(1.0 - np.exp(-(V+40.0) / 10.0))
@@ -277,58 +283,79 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
277283
plt.rcParams['figure.figsize'] = [10, 7]
278284

279285
plt.close()
280-
fig=plt.figure()
286+
287+
fig=plt.figure(figsize=(7, self.num_plots * 2))
281288
fig.canvas.header_visible = False
289+
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
282290

283291
if self.injected_current_plot:
284-
ax1 = plt.subplot(5,1,1)
285-
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
292+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
286293
plt.title('Simulation of Hodgkin Huxley model neuron')
287-
288294
if self.is_vclamp():
289295
i_inj_values = [self.I_inj_vclamp(t,v) for t,v in zip(self.t,V)]
290296
else:
291297
i_inj_values = [self.I_inj(t) for t in self.t]
292298

299+
if self.is_vclamp(): plt.ylim(-2000,3000)
300+
293301
plt.plot(self.t, i_inj_values, 'k')
294302
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
295-
if self.is_vclamp(): plt.ylim(-2000,3000)
303+
304+
self.plot_count += 1
296305

297306

298307
if self.gating_plot:
299-
plt.subplot(5,1,2, sharex = ax1)
308+
try:
309+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
310+
except NameError:
311+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
312+
plt.title('Simulation of Hodgkin Huxley model neuron')
300313
plt.plot(self.t, m, 'r', label='m')
301314
plt.plot(self.t, h, 'g', label='h')
302315
plt.plot(self.t, n, 'b', label='n')
303316
plt.ylabel('Gating Variable')
304317
plt.legend()
318+
self.plot_count += 1
305319

306320
if self.cond_dens_plot:
307-
plt.subplot(5,1,3, sharex = ax1)
321+
try:
322+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
323+
except NameError:
324+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
325+
plt.title('Simulation of Hodgkin Huxley model neuron')
308326
plt.plot(self.t, gna, 'c', label='$g_{Na}$')
309327
plt.plot(self.t, gk, 'y', label='$g_{K}$')
310328
plt.ylabel('Cond. dens')
311329
plt.legend()
330+
self.plot_count += 1
312331

313332
if self.current_plot:
314-
plt.subplot(5,1,4, sharex = ax1)
333+
try:
334+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
335+
except NameError:
336+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
337+
plt.title('Simulation of Hodgkin Huxley model neuron')
315338
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
316339
plt.plot(self.t, ik, 'y', label='$I_{K}$')
317340
plt.plot(self.t, il, 'm', label='$I_{L}$')
318341
plt.ylabel('Current')
319342
plt.legend()
343+
self.plot_count += 1
320344

321345
if self.memb_pot_plot:
322-
plt.subplot(5,1,5, sharex = ax1)
346+
try:
347+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
348+
except NameError:
349+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
350+
plt.title('Simulation of Hodgkin Huxley model neuron')
323351
plt.plot(self.t, V, 'k')
324352
plt.ylabel('V (mV)')
325353
plt.xlabel('t (ms)')
326354
if not self.is_vclamp(): plt.ylim(-85,60)
327355
#plt.ylim(-1, 40)
356+
self.plot_count += 1
328357

329358
plt.tight_layout()
330-
331-
332359
plt.show()
333360

334361
if __name__ == '__main__':

notebooks/Python_HH_version/ui_widget.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ def highlight_slider():
205205
button_row=ipywidgets.HBox([reset_button,showValue_togglebtn])
206206

207207
#plot selectors
208-
injected_current_plot_value = ipywidgets.ToggleButton(value=True, description="Current injection plot", disabled=True,)
209-
gating_plot_value = ipywidgets.ToggleButton(value=False, description="Gating variables", disabled=False,)
210-
cond_dens_plot_value = ipywidgets.ToggleButton(value=False, description="Conductance density", disabled=False,)
211-
current_plot_value = ipywidgets.ToggleButton(value=False, description="Current", disabled=False,)
212-
memb_pot_plot_value = ipywidgets.ToggleButton(value=False, description="Memb pot", disabled=False,)
213-
plot_selection_row=ipywidgets.HBox([injected_current_plot_value, gating_plot_value, cond_dens_plot_value, current_plot_value, memb_pot_plot_value])
208+
header_plotting = ipywidgets.HTMLMath(value=r"<b> Select plots</b>")
209+
injected_current_plot_value = ipywidgets.Checkbox(value=True, description="Current injection plot", disabled=False,)
210+
gating_plot_value = ipywidgets.Checkbox(value=True, description="Gating variables", disabled=False,)
211+
cond_dens_plot_value = ipywidgets.Checkbox(value=True, description="Conductance density", disabled=False,)
212+
current_plot_value = ipywidgets.Checkbox(value=True, description="Current", disabled=False,)
213+
memb_pot_plot_value = ipywidgets.Checkbox(value=True, description="Memb pot", disabled=False,)
214+
plot_selection_row=ipywidgets.VBox([header_plotting, ipywidgets.HBox([injected_current_plot_value, gating_plot_value, cond_dens_plot_value]), ipywidgets.HBox([current_plot_value, memb_pot_plot_value])])
214215

215216
#layout vertically all the widgets defined above
216217
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,runMode_iclamp,runMode_vclamp,button_row,defalultValues,plot_selection_row])

0 commit comments

Comments
 (0)