@@ -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
334361if __name__ == '__main__' :
0 commit comments