def run_democlamp(cell, dend, vsteps=[-60,-70,-60], tsteps=[10,50,100]): """ Does some stuff. """ f1 = pylab.figure(1) gs = GS.GridSpec(2, 2, width_ratios=[1, 1], height_ratios=[1, 1]) # note numbering for insets goes from 1 (upper right) to 4 (lower right) # counterclockwise pA = f1.add_subplot(gs[0]) pAi = INSETS.inset_axes(pA, width="66%", height="40%", loc=2) pB = f1.add_subplot(gs[1]) pBi = INSETS.inset_axes(pB, width="66%", height="40%", loc=4) pC = f1.add_subplot(gs[2]) pCi = INSETS.inset_axes(pC, width="66%", height="40%", loc=2) pD = f1.add_subplot(gs[3]) pDi = INSETS.inset_axes(pD, width="66%", height="40%", loc=1) #h.topology() Ld = 0.5 Ld2 = 1.0 VClamp = h.SEClamp(0.5, cell) VClamp.dur1 = tsteps[0] VClamp.amp1 = vsteps[0] VClamp.dur2 = tsteps[1] VClamp.amp2 = vsteps[1] VClamp.dur3 = tsteps[2] VClamp.amp3 = vsteps[2] Rs0 = 10. VClamp.rs = Rs0 compensation = [0., 70., 95.] cms = [cell.cm*(100.-c)/100. for c in compensation] vrec = h.iStim(Ld, sec=dend[0]) vrec.delay = 0 vrec.dur = 1e9 # these actually do not matter... vrec.iMax = 0.0 vrec2 = h.iStim(Ld2, sec=dend[0]) vrec2.delay = 0 vrec2.dur = 1e9 # these actually do not matter... vrec2.iMax = 0.0 stim = {} stim['NP'] = 1 stim['Sfreq'] = 20 # stimulus frequency stim['delay'] = tsteps[0] stim['dur'] = tsteps[1] stim['amp'] = vsteps[1] stim['PT'] = 0.0 stim['hold'] = vsteps[0] # (secmd, maxt, tstims) = make_pulse(stim) tend = 79.5 linetype = ['-', '-', '-'] linethick = [0.5, 0.75, 1.25] linecolor = [[0.66, 0.66, 0.66], [0.4, 0.4, 0.3], 'k'] n = 0 vcmds = [-70, -20] vplots = [(pA, pAi, pC, pCi), (pB, pBi, pD, pDi)] for m, VX in enumerate(vcmds): stim['amp'] = VX pl = vplots[m] print m, VX (secmd, maxt, tstims) = make_pulse(stim) for n, rsc in enumerate(compensation): vec={} for var in ['VCmd', 'i_inj', 'time', 'Vsoma', 'Vdend', 'Vdend2', 'VCmdR']: vec[var] = h.Vector() VClamp.rs = Rs0*(100.-rsc)/100. cell.cm = cms[n] # print VClamp.rs, cell.cm, VClamp.rs*cell.cm vec['VCmd'] = h.Vector(secmd) vec['Vsoma'].record(cell(0.5)._ref_v, sec=cell) vec['Vdend'].record(dend[0](Ld)._ref_v, sec=dend[0]) vec['time'].record(h._ref_t) vec['i_inj'].record(VClamp._ref_i, sec=cell) vec['VCmdR'].record(VClamp._ref_vc, sec=cell) VClamp.amp2 = VX # vec['VCmd'].play(VClamp.amp2, h.dt, 0, sec=cell) h.tstop = tend h.init() h.finitialize(-60) h.run() vc = np.asarray(vec['Vsoma']) tc = np.asarray(vec['time']) # now plot the data, raw and as insets for k in [0, 1]: pl[k].plot(vec['time'], vec['i_inj'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n]) yl = pl[k].get_ylim() if k == 0: pass #pl[k].set_ylim([1.5*yl[0], -1.5*yl[1]]) else: pass for k in [2,3]: pl[k].plot(vec['time'], vec['Vsoma'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n]) pl[k].plot(vec['time'], vec['VCmdR'], color=linecolor[n], linestyle = '--', linewidth=1, dashes=(1,1)) pl[k].plot(vec['time'], vec['Vdend'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n], dashes=(3,3)) if VX < vsteps[0]: pl[k].set_ylim([-72, -40]) else: pl[k].set_ylim([-62,VX+30]) ptx = 10.8 pBi.set_xlim([9.8, ptx]) pAi.set_xlim([9.8, ptx]) PH.setX(pAi, pCi) PH.setX(pBi, pDi) pD.set_ylim([-65, 10]) # PH.setY(pC, pCi) # match Y limits PH.cleanAxes([pA, pAi, pB, pBi, pC, pCi, pD, pDi]) PH.formatTicks([pA, pB, pC, pD], axis='x', fmt='%d') PH.formatTicks([pC, pD], axis='y', fmt='%d') PH.calbar(pAi, [ptx-1, 0, 0.2, 2.]) PH.calbar(pCi, [ptx-1, -50., 0.2, 10]) PH.calbar(pBi, [ptx-1, 0, 0.2, 10]) PH.calbar(pDi, [ptx-1, -50., 0.2, 20]) pylab.draw() pylab.show()
def plot(self): sizer = OrderedDict( [ ('A', { 'pos': [0.12, 0.2, 0.15, 0.5] }), ('B', { 'pos': [0.45, 0.2, 0.15, 0.5] }), ('C', { 'pos': [0.72, 0.2, 0.15, 0.5] }), ] ) # dict elements are [left, width, bottom, height] for the axes in the plot. n_panels = len(sizer.keys()) gr = [(a, a + 1, 0, 1) for a in range(0, n_panels) ] # just generate subplots - shape does not matter axmap = OrderedDict(zip(sizer.keys(), gr)) P = PH.Plotter((n_panels, 1), axmap=axmap, label=True, labeloffset=[-0.15, 0.08], fontsize={ 'tick': 8, 'label': 10, 'panel': 14 }, figsize=(5., 3.)) P.resize(sizer) # perform positioning magic # P.axdict['A'].plot(np.ones(len(self.intvls[self.group_names[0]])), 1000./np.array(self.intvls[self.group_names[0]]), # 'ko', markersize=4.0, label=self.group_names[0]) # P.axdict['A'].plot(1+np.ones(len(self.intvls[self.group_names[1]])), 1000./np.array(self.intvls[self.group_names[1]]), # 'bs', markersize=4.0, label=self.group_names[1]) # P.axdict['B'].plot(np.ones(len(self.amps[self.group_names[0]])), self.amps[self.group_names[0]], # 'ko', markerfacecolor='k', markeredgecolor='k', markersize=4.0, markeredgewidth=1) # P.axdict['B'].plot(1.0 + np.ones(len(self.amps[self.group_names[1]])), self.amps[self.group_names[1]], # 'bs', markerfacecolor='b', markeredgecolor='b', markersize=4.0, markeredgewidth=1) # P.axdict['B'].plot(0.2 + np.ones(len(self.meanamps[self.group_names[0]])), self.meanamps[self.group_names[0]], # 'ko', markerfacecolor='w', markeredgecolor='k', markersize=4.0, markeredgewidth=1) # P.axdict['B'].plot(1.2 + np.ones(len(self.meanamps[self.group_names[1]])), self.meanamps[self.group_names[1]], # 'bs', markerfacecolor='w', markeredgecolor='b', markersize=4.0, markeredgewidth=1) for a in ['A', 'B', 'C']: PH.formatTicks(P.axdict[a], font='Helvetica') sns.swarmplot(x='Genotype', y='Intvls', data=self.pddata, ax=P.axdict['A']) sns.boxplot(x='Genotype', y='Intvls', data=self.pddata, ax=P.axdict['A'], color="0.8") sns.swarmplot(x='Genotype', y='Amp', data=self.pddata, ax=P.axdict['B']) sns.boxplot(x='Genotype', y='Amp', data=self.pddata, ax=P.axdict['B'], color="0.8") sns.swarmplot(x='Genotype', y='MeanAmp', data=self.pddata, ax=P.axdict['C']) sns.boxplot(x='Genotype', y='MeanAmp', data=self.pddata, ax=P.axdict['C'], color="0.8") P.axdict['A'].set_ylim(0.0, 25.) P.axdict['A'].set_ylabel('Event Frequency (Hz)') P.axdict['B'].set_ylim(0.0, 30.) P.axdict['B'].set_ylabel('Median Amplitude (pA)') P.axdict['C'].set_ylabel('Mean Amplitude (pA)') P.axdict['C'].set_ylim(0.0, 30.) # P.axdict['A'].set_xlabel('Group') # P.axdict['B'].set_xlabel('Group') # P.axdict['A'].set_xlim(0.5, 2.5) # P.axdict['B'].set_xlim(0.5, 2.5) # P.axdict['B'].set_xlim(0.5, 2.5) # P.axdict['A'].legend() P.figure_handle.suptitle(self.filename.replace('_', '\_')) mpl.savefig('msummary_%s.pdf' % self.experiment_id) mpl.show()