plt.plot(t_vec, i_vec, color=lcmaps.get_color(0)) lplot.save_plt(plt, "cs_ap_scaled_with_current", ".") plt.close() print "plotting scaled ap" plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) ax.set_ylabel(r"Mem. Pot. \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Time \textbf{[\si{\milli\second}]}") plt.plot(t_vec, v_vec, color=lcmaps.get_color(0)) lplot.save_plt(plt, "cs_ap_scaled", ".") plt.close() freqs, amps, phase = \ de.find_freq_and_fft(p['dt'],v_vec, length=v_vec.shape[-1]*1, f_cut=3) # Remove the first coefficient as we don't care about the baseline. freqs = np.delete(freqs, 0) amps = np.delete(amps, 0) print "plotting fourier" plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) ax.set_ylabel(r"Mem. Pot. \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Frequency \textbf{[\si{\kilo\hertz}]}") plt.plot(freqs, amps, color=lcmaps.get_color(0)) lplot.save_plt(plt, "cs_ap_fourier", ".") plt.close() # Save the actionpotential to file.
def plot(self, dir_plot): """ Plotting stats about the spikes. """ # pylint: disable=too-many-locals data = self.data run_param = self.run_param # String to put before output to the terminal. str_start = self.name str_start += " "*(20 - len(self.name)) + ":" # Set global matplotlib parameters. LFPy_util.plot.set_rc_param() # Plot spike amps I {{{1 # fname = self.name + '_spike_amps_I' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['amps_I_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between(data['r_vec'], data['amps_I_mean'] - data['amps_I_std'], data['amps_I_mean'] + data['amps_I_std'], color=lcmaps.get_color(0), alpha=0.2) ax.set_ylabel(r"Amplitude \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Distance from Soma \textbf{[\si{\micro\metre}]}") lplot.save_plt(plt, fname, dir_plot) plt.close() # }}} # # {{{ Plot spike amps I log fname = self.name + '_spike_amps_I_log' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['amps_I_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between(data['r_vec'], data['amps_I_mean'] - data['amps_I_std'], data['amps_I_mean'] + data['amps_I_std'], color=lcmaps.get_color(0), alpha=0.2) # Ugly way to put in some graphs for power laws. # Left side. x0 = data['r_vec'][0] x1 = data['r_vec'][1] y0 = data['amps_I_mean'][0] for p in [1.0, 2.0, 3.0]: y1 = np.power( 1.0 / data['r_vec'][1], p) * \ data['amps_I_mean'][ 0] / \ np.power(1.0 / data['r_vec'][0], p) ax.plot([x0, x1], [y0, y1], color='black') ax.annotate( '-'+str(int(p)), xy=(x1,y1), xytext=(x1*1.01, y1*0.95), ) # Right side. x0 = data['r_vec'][-3] x1 = data['r_vec'][-1] y1 = data['amps_I_mean'][-1] for p in [1.0, 2.0, 3.0]: y0 = np.power(1.0 / data['r_vec'][-3], p) * \ data['amps_I_mean'][-1] / \ np.power(1.0 / data['r_vec'][-1], p) ax.plot([x0, x1], [y0, y1], color='black') ax.annotate( '-'+str(int(p)), xy=(x0,y0), xytext=(x0*0.99, y0*0.95), horizontalalignment='right', ) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlim([data['r_vec'].min(), data['r_vec'].max()]) ticker = mpl.ticker.MaxNLocator(nbins=7) ax.xaxis.set_major_locator(ticker) ax.xaxis.get_major_formatter().labelOnlyBase = False # ticker = mpl.ticker.MaxNLocator(nbins=7) # ax.yaxis.set_major_locator(ticker) # ax.yaxis.get_major_formatter().labelOnlyBase = False # Set a label formatter to use normal numbers. ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.set_ylabel(r"Amplitude \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Distance from Soma \textbf{[\si{\micro\metre}]}") lplot.save_plt(plt, fname, dir_plot) plt.close() # }}} # Plot spike amps II {{{1 # fname = self.name + '_spike_amps_II' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['amps_II_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between(data['r_vec'], data['amps_II_mean'] - data['amps_II_std'], data['amps_II_mean'] + data['amps_II_std'], color=lcmaps.get_color(0), alpha=0.2) ax.set_ylabel("Amplitude") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # {{{ Plot spike amps II log fname = self.name + '_spike_amps_II_log' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['amps_II_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between(data['r_vec'], data['amps_II_mean'] - data['amps_II_std'], data['amps_II_mean'] + data['amps_II_std'], color=lcmaps.get_color(0), alpha=0.2) # Ugly way to put in some graphs for power laws. # Left side. x0 = data['r_vec'][0] x1 = data['r_vec'][1] y0 = data['amps_II_mean'][0] for p in [1.0, 2.0, 3.0]: y1 = np.power( 1.0 / data['r_vec'][1], p) * \ data['amps_II_mean'][ 0] / \ np.power(1.0 / data['r_vec'][0], p) ax.plot([x0, x1], [y0, y1], color='black') ax.annotate( '-'+str(int(p)), xy=(x1,y1), xytext=(x1*1.01, y1*0.95), ) # Right side. x0 = data['r_vec'][-3] x1 = data['r_vec'][-1] y1 = data['amps_II_mean'][-1] for p in [1.0, 2.0, 3.0]: y0 = np.power(1.0 / data['r_vec'][-3], p) * \ data['amps_II_mean'][-1] / \ np.power(1.0 / data['r_vec'][-1], p) ax.plot([x0, x1], [y0, y1], color='black') ax.annotate( '-'+str(int(p)), xy=(x0,y0), xytext=(x0*0.99, y0*0.95), horizontalalignment='right', ) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlim([data['r_vec'].min(), data['r_vec'].max()]) ticker = mpl.ticker.MaxNLocator(nbins=7) ax.xaxis.set_major_locator(ticker) ax.xaxis.get_major_formatter().labelOnlyBase = False # ticker = mpl.ticker.MaxNLocator(nbins=7) # ax.yaxis.set_major_locator(ticker) # ax.yaxis.get_major_formatter().labelOnlyBase = False # Set a label formatter to use normal numbers. ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.set_ylabel(r"Amplitude \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Distance from Soma \textbf{[\si{\micro\metre}]}") lplot.save_plt(plt, fname, dir_plot) plt.close() # }}} # Plot spike width I {{{1 # fname = self.name + '_spike_width_I' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['widths_I_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between(data['r_vec'], data['widths_I_mean'] - data['widths_I_std'], data['widths_I_mean'] + data['widths_I_std'], color=lcmaps.get_color(0), alpha=0.2) ax.set_ylabel("Spike Width") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot spike widths II {{{1 # fname = self.name + '_spike_width_II' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['widths_II_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between( data['r_vec'], data['widths_II_mean'] - data['widths_II_std'], data['widths_II_mean'] + data['widths_II_std'], color=lcmaps.get_color(0), alpha=0.2) ax.set_ylabel("Spike Width") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot spike widths III {{{1 # fname = self.name + '_spike_width_III' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['r_vec'], data['widths_III_mean'], color=lcmaps.get_color(0), marker='o', markersize=5, ) ax.fill_between( data['r_vec'], data['widths_III_mean'] - data['widths_III_std'], data['widths_III_mean'] + data['widths_III_std'], color=lcmaps.get_color(0), alpha=0.2) ax.set_ylabel("Spike Width") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot morphology xz {{{ # LFPy_util.plot.morphology(data['poly_morph_xz'], data['poly_morph_axon_xz'], elec_x=data['elec_x'], elec_y=data['elec_z'], fig_size=lplot.size_square, fname=self.name + "_morph_elec_xz", plot_save_dir=dir_plot, x_label='x', y_label='z', show=False) # }}} # # Spike to plot. elec_index = run_param['n']/2 # title_str = r"Distance from Soma = \SI{{{}}}{{\micro\metre}}" # title_str = title_str.format(round(data['r_vec'][elec_index]),2) c = lcmaps.get_short_color_array(2 + 1) # Plot middle electrode spike {{{1 # fname = self.name + '_middle_elec_spike' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['spikes_t_vec'], data['spikes'][elec_index], color=c[0]) # Trace I plt.plot(data['spikes_t_vec'], data['widths_I_trace'][elec_index], color=c[1], ) # Trace II plt.plot(data['spikes_t_vec'], data['widths_II_trace'][elec_index], color=c[1]) # plt.title(title_str) # Save plt. lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot middle electrode spike freq {{{1 # fname = self.name + '_middle_elec_spike_fourier' freq, amp, phase = de.find_freq_and_fft( data['dt'], data['spikes'][elec_index], ) # Remove the first coefficient as we don't care about the baseline. freq = np.delete(freq, 0) amp = np.delete(amp, 0) # Delete frequencies above the option. if self.plot_param['freq_end'] is not None: idx = min( range(len(freq)), key=lambda i: abs(freq[i] - self.plot_param['freq_end']) ) freq = freq[0:idx] amp = amp[0:idx] print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) plt.plot(freq, amp, color=lcmaps.get_color(0)) # plt.title(title_str) ax.set_ylabel(r'Amplitude \textbf[$\mathbf{mV}$\textbf]') ax.set_xlabel(r'Frequency \textbf[$\mathbf{kHz}$\textbf]') lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot middle electrode signal {{{1 # fname = self.name + '_middle_elec' print "plotting :", fname c = lcmaps.get_short_color_array(2 + 1) plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['t_vec'], data['LFP'][elec_index], color=lcmaps.get_color(0)) # plt.title(title_str) # Save plt. lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot middle electrode signal freq {{{1 # fname = self.name + '_middle_elec_fourier' freq, amp, phase = de.find_freq_and_fft( data['dt'], data['LFP'][elec_index], ) # Remove the first coefficient as we don't care about the baseline. freq = np.delete(freq, 0) amp = np.delete(amp, 0) if self.plot_param['freq_end'] is not None: idx = min( range(len(freq)), key=lambda i: abs(freq[i] - self.plot_param['freq_end']) ) freq = freq[0:idx] amp = amp[0:idx] print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) plt.plot(freq, amp, color=lcmaps.get_color(0)) ax.set_ylabel(r'Amplitude \textbf[$\mathbf{mV}$\textbf]') ax.set_xlabel(r'Frequency \textbf[$\mathbf{kHz}$\textbf]') # plt.title(title_str) lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # if self.plot_param['plot_detailed']: # Create the directory if it does not exist. sub_dir = os.path.join(dir_plot, self.name + "_detailed") if not os.path.exists(sub_dir): os.makedirs(sub_dir) # t = len(run_param['theta']) # p = run_param['n_phi'] p = 1 n = run_param['n'] # This title string should be formatted. title_str = r"Distance from Soma = \SI{{{}}}{{\micro\metre}}" cnt = 0 for j in xrange(p): for k in xrange(n): title_str_1 = title_str.format(data['r_vec'][k]) # Plot all elec spikes {{{1 # fname = self.name + '_elec_p_{}_n_{}'.format(j * 360 / p, k) print "plotting :", fname c = lcmaps.get_short_color_array(2 + 1) plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['spikes_t_vec'], data['spikes'][cnt], color=c[0]) # Trace I plt.plot(data['spikes_t_vec'], data['widths_I_trace'][cnt], color=c[1], ) # Trace II plt.plot(data['spikes_t_vec'], data['widths_II_trace'][cnt], color=c[1]) # Trace III plt.plot(data['spikes_t_vec'], data['widths_III_trace'][cnt], color=c[1]) # plt.title(title_str_1) # Save plt. lplot.save_plt(plt, fname, sub_dir) plt.close() # 1}}} # # Plot all elec spikes freq {{{1 # # Fourier plot. fname = self.name + '_freq_elec_p_{}_n_{}'.format(j * 360 / p, k) freq, amp, phase = de.find_freq_and_fft( data['dt'], data['spikes'][cnt], ) # Remove the first coefficient as we don't care about the baseline. freq = np.delete(freq, 0) amp = np.delete(amp, 0) if self.plot_param['freq_end'] is not None: idx = min( range(len(freq)), key=lambda i: abs(freq[i] - self.plot_param['freq_end']) ) freq = freq[0:idx] amp = amp[0:idx] print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) plt.plot(freq, amp, color=c[0]) ax.set_ylabel(r'Amplitude \textbf[$\mathbf{mV}$\textbf]') ax.set_xlabel(r'Frequency \textbf[$\mathbf{kHz}$\textbf]') # plt.title(title_str_1) lplot.save_plt(plt, fname, sub_dir) plt.close() # 1}}} # cnt += 1
def plot(self, dir_plot): """ Plotting stats about the spikes. """ # pylint: disable=too-many-locals data = self.data run_param = self.run_param # String to put before output to the terminal. str_start = self.name str_start += " "*(20 - len(self.name)) + ":" # Set global matplotlib parameters. LFPy_util.plot.set_rc_param() # 3D plot {{{1 # fname = self.name + "_elec_pos" c = lplot.get_short_color_array(5)[2] fig = plt.figure(figsize=lplot.size_common) ax = fig.add_subplot(111, projection='3d') cnt = 0 for i, theta in enumerate(run_param['theta']): for j in xrange(run_param['n_phi']): for k in xrange(run_param['n']): ax.scatter(data['elec_x'][cnt], data['elec_y'][cnt], data['elec_z'][cnt], c=c) cnt += 1 ax.set_xlim(-run_param['R'], run_param['R']) ax.set_ylim(-run_param['R'], run_param['R']) ax.set_zlim(-run_param['R'], run_param['R']) ax.set_xlabel("X axis") ax.set_ylabel("Y axis") ax.set_zlabel("Z axis") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot spike amps I {{{1 # fname = self.name + '_spike_amps_I' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot c = lplot.get_short_color_array(data['amps_I_mean'].shape[0] + 1) for t in xrange(data['amps_I_mean'].shape[0]): label = r'$\theta = {}\degree$'.format(run_param['theta'][t]) plt.plot(data['r_vec'], data['amps_I_mean'][t], color=c[t], marker='o', markersize=5, label=label) ax.fill_between(data['r_vec'], data['amps_I_mean'][t] - data['amps_I_std'][t], data['amps_I_mean'][t] + data['amps_I_std'][t], color=c[t], alpha=0.2) handles, labels = ax.get_legend_handles_labels() # Position the legen on the right side of the plot. ax.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.0, 1.04), ) ax.set_ylabel(r"Amplitude \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Distance from Soma \textbf{[\si{\micro\metre}]}") lplot.save_plt(plt, fname, dir_plot) plt.close() # }}} # # {{{ Plot spike amps I log fname = self.name + '_spike_amps_I_log' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot c = lplot.get_short_color_array(data['amps_I_mean'].shape[0] + 1) for t in xrange(data['amps_I_mean'].shape[0]): label = r'$\theta = {}\degree$'.format(run_param['theta'][t]) plt.plot(data['r_vec'], data['amps_I_mean'][t], color=c[t], marker='o', markersize=5, label=label) ax.fill_between(data['r_vec'], data['amps_I_mean'][t] - data['amps_I_std'][t], data['amps_I_mean'][t] + data['amps_I_std'][t], color=c[t], alpha=0.2) # # Ugly way to put in some graphs for power laws. # # Left side. # x0 = data['r_vec'][0] # x1 = data['r_vec'][1] # y0 = data['amps_I_mean'][t, 0] # for p in [1.0, 2.0, 3.0]: # y1 = np.power( 1.0 / data['r_vec'][1], p) * \ # data['amps_I_mean'][t, 0] / \ # np.power(1.0 / data['r_vec'][0], p) # ax.plot([x0, x1], [y0, y1], color='black') # # Right side. # x0 = data['r_vec'][-3] # x1 = data['r_vec'][-1] # y1 = data['amps_I_mean'][t,-1] # for p in [1.0, 2.0, 3.0]: # y0 = np.power(1.0 / data['r_vec'][-3], p) * \ # data['amps_I_mean'][t, -1] / \ # np.power(1.0 / data['r_vec'][-1], p) # ax.plot([x0, x1], [y0, y1], color='black') handles, labels = ax.get_legend_handles_labels() # Position the legen on the right side of the plot. ax.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.0, 1.04), ) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlim([data['r_vec'].min(), data['r_vec'].max()]) ticker = mpl.ticker.MaxNLocator(nbins=7) ax.xaxis.set_major_locator(ticker) ax.xaxis.get_major_formatter().labelOnlyBase = False # ticker = mpl.ticker.MaxNLocator(nbins=7) # ax.yaxis.set_major_locator(ticker) # ax.yaxis.get_major_formatter().labelOnlyBase = False # Set a label formatter to use normal numbers. ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.set_ylabel(r"Amplitude \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Distance from Soma \textbf{[\si{\micro\metre}]}") lplot.save_plt(plt, fname, dir_plot) plt.close() # }}} # Plot spike amps II {{{1 # fname = self.name + '_spike_amps_II' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot c = lplot.get_short_color_array(data['amps_II_mean'].shape[0] + 1) for t in xrange(data['amps_II_mean'].shape[0]): label = r'$\theta = {}\degree$'.format(run_param['theta'][t]) plt.plot(data['r_vec'], data['amps_II_mean'][t], color=c[t], marker='o', markersize=5, label=label) ax.fill_between(data['r_vec'], data['amps_II_mean'][t] - data['amps_II_std'][t], data['amps_II_mean'][t] + data['amps_II_std'][t], color=c[t], alpha=0.2) handles, labels = ax.get_legend_handles_labels() # Position the legen on the right side of the plot. ax.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.0, 1.04), ) ax.set_ylabel("Amplitude") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # {{{ Plot spike amps II log fname = self.name + '_spike_amps_II_log' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot c = lplot.get_short_color_array(data['amps_II_mean'].shape[0] + 1) for t in xrange(data['amps_II_mean'].shape[0]): label = r'$\theta = {}\degree$'.format(run_param['theta'][t]) plt.plot(data['r_vec'], data['amps_II_mean'][t], color=c[t], marker='o', markersize=5, label=label) ax.fill_between(data['r_vec'], data['amps_II_mean'][t] - data['amps_II_std'][t], data['amps_II_mean'][t] + data['amps_II_std'][t], color=c[t], alpha=0.2) handles, labels = ax.get_legend_handles_labels() # Position the legen on the right side of the plot. ax.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.0, 1.04), ) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlim([data['r_vec'].min(), data['r_vec'].max()]) ticker = mpl.ticker.MaxNLocator(nbins=7) ax.xaxis.set_major_locator(ticker) ax.xaxis.get_major_formatter().labelOnlyBase = False # ticker = mpl.ticker.MaxNLocator(nbins=7) # ax.yaxis.set_major_locator(ticker) # ax.yaxis.get_major_formatter().labelOnlyBase = False # Set a label formatter to use normal numbers. ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.set_ylabel(r"Amplitude \textbf{[\si{\milli\volt}]}") ax.set_xlabel(r"Distance from Soma \textbf{[\si{\micro\metre}]}") lplot.save_plt(plt, fname, dir_plot) plt.close() # }}} # Plot spike width I {{{1 # fname = self.name + '_spike_width_I' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot c = lplot.get_short_color_array(data['widths_I_mean'].shape[0] + 1) for t in xrange(data['widths_I_mean'].shape[0]): label = r'$\theta = {}\degree$'.format(run_param['theta'][t]) plt.plot(data['r_vec'], data['widths_I_mean'][t], color=c[t], marker='o', markersize=5, label=label) ax.fill_between(data['r_vec'], data['widths_I_mean'][t] - data['widths_I_std'][t], data['widths_I_mean'][t] + data['widths_I_std'][t], color=c[t], alpha=0.2) handles, labels = ax.get_legend_handles_labels() # Position the legen on the right side of the plot. ax.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.0, 1.04), ) ax.set_ylabel("Spike Width") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot spike widths II {{{1 # fname = self.name + '_spike_width_II' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot c = lplot.get_short_color_array(data['widths_II_mean'].shape[0] + 1) for t in xrange(data['widths_II_mean'].shape[0]): label = r'$\theta = {}\degree$'.format(run_param['theta'][t]) plt.plot(data['r_vec'], data['widths_II_mean'][t], color=c[t], marker='o', markersize=5, label=label) ax.fill_between( data['r_vec'], data['widths_II_mean'][t] - data['widths_II_std'][t], data['widths_II_mean'][t] + data['widths_II_std'][t], color=c[t], alpha=0.2) handles, labels = ax.get_legend_handles_labels() # Position the legen on the right side of the plot. ax.legend(handles, labels, loc='upper left', bbox_to_anchor=(1.0, 1.04), ) ax.set_ylabel("Spike Width") ax.set_xlabel("Distance from Soma") lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot morphology {{{1 # LFPy_util.plot.morphology(data['poly_morph'], data['poly_morph_axon'], elec_x=data['elec_x'], elec_y=data['elec_y'], fig_size=lplot.size_common, fname=self.name + "_morph_elec_xy", plot_save_dir=dir_plot, show=False) # 1}}} # # Plot morphology xz {{{ # LFPy_util.plot.morphology(data['poly_morph_xz'], data['poly_morph_axon_xz'], elec_x=data['elec_x'], elec_y=data['elec_z'], fig_size=lplot.size_common, fname=self.name + "_morph_elec_xz", plot_save_dir=dir_plot, show=False) # }}} # # Spike to plot. elec_index = run_param['n']/2 # title_str = r"Distance from Soma = \SI{{{}}}{{\micro\metre}}" # title_str = title_str.format(round(data['r_vec'][elec_index]),2) c = lplot.get_short_color_array(2 + 1) # Plot middle electrode spike {{{1 # fname = self.name + '_middle_elec_spike' print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['spikes_t_vec'], data['spikes'][elec_index], color=c[0]) # Trace I plt.plot(data['spikes_t_vec'], data['widths_I_trace'][elec_index], color=c[1], ) # Trace II plt.plot(data['spikes_t_vec'], data['widths_II_trace'][elec_index], color=c[1]) # plt.title(title_str) # Save plt. lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot middle electrode spike freq {{{1 # fname = self.name + '_middle_elec_spike_fourier' freq, amp, phase = de.find_freq_and_fft( data['dt'], data['spikes'][elec_index], ) # Remove the first coefficient as we don't care about the baseline. freq = np.delete(freq, 0) amp = np.delete(amp, 0) # Delete frequencies above the option. if self.plot_param['freq_end'] is not None: idx = min( range(len(freq)), key=lambda i: abs(freq[i] - self.plot_param['freq_end']) ) freq = freq[0:idx] amp = amp[0:idx] print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) plt.plot(freq, amp, color=c[0]) # plt.title(title_str) ax.set_ylabel(r'Amplitude \textbf[$\mathbf{mV}$\textbf]') ax.set_xlabel(r'Frequency \textbf[$\mathbf{kHz}$\textbf]') lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot middle electrode signal {{{1 # fname = self.name + '_middle_elec' print "plotting :", fname c = lplot.get_short_color_array(2 + 1) plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['t_vec'], data['LFP'][elec_index], color=c[0]) # plt.title(title_str) # Save plt. lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # # Plot middle electrode signal freq {{{1 # fname = self.name + '_middle_elec_fourier' freq, amp, phase = de.find_freq_and_fft( data['dt'], data['LFP'][elec_index], ) # Remove the first coefficient as we don't care about the baseline. freq = np.delete(freq, 0) amp = np.delete(amp, 0) if self.plot_param['freq_end'] is not None: idx = min( range(len(freq)), key=lambda i: abs(freq[i] - self.plot_param['freq_end']) ) freq = freq[0:idx] amp = amp[0:idx] print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) plt.plot(freq, amp, color=c[0]) ax.set_ylabel(r'Amplitude \textbf[$\mathbf{mV}$\textbf]') ax.set_xlabel(r'Frequency \textbf[$\mathbf{kHz}$\textbf]') # plt.title(title_str) lplot.save_plt(plt, fname, dir_plot) plt.close() # 1}}} # if self.plot_param['plot_detailed']: # Create the directory if it does not exist. sub_dir = os.path.join(dir_plot, self.name + "_detailed") if not os.path.exists(sub_dir): os.makedirs(sub_dir) t = len(run_param['theta']) # p = run_param['n_phi'] p = 1 n = run_param['n'] # This title string should be formatted. title_str = r"Distance from Soma = \SI{{{}}}{{\micro\metre}}" cnt = 0 for i in xrange(t): for j in xrange(p): for k in xrange(n): title_str_1 = title_str.format(data['r_vec'][k]) # Plot all elec spikes {{{1 # fname = self.name + '_elec_t_{}_p_{}_n_{}'.format( run_param['theta'][i], j * 360 / p, k) print "plotting :", fname c = lplot.get_short_color_array(2 + 1) plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) # Plot plt.plot(data['spikes_t_vec'], data['spikes'][cnt], color=c[0]) # Trace I plt.plot(data['spikes_t_vec'], data['widths_I_trace'][cnt], color=c[1], ) # Trace II plt.plot(data['spikes_t_vec'], data['widths_II_trace'][cnt], color=c[1]) # plt.title(title_str_1) # Save plt. lplot.save_plt(plt, fname, sub_dir) plt.close() # 1}}} # # Plot all elec spikes freq {{{1 # # Fourier plot. fname = self.name + '_freq_elec_t_{}_p_{}_n_{}'.format( run_param['theta'][i], j * 360 / p, k) freq, amp, phase = de.find_freq_and_fft( data['dt'], data['spikes'][cnt], ) # Remove the first coefficient as we don't care about the baseline. freq = np.delete(freq, 0) amp = np.delete(amp, 0) if self.plot_param['freq_end'] is not None: idx = min( range(len(freq)), key=lambda i: abs(freq[i] - self.plot_param['freq_end']) ) freq = freq[0:idx] amp = amp[0:idx] print "plotting :", fname plt.figure(figsize=lplot.size_common) ax = plt.gca() lplot.nice_axes(ax) plt.plot(freq, amp, color=c[0]) ax.set_ylabel(r'Amplitude \textbf[$\mathbf{mV}$\textbf]') ax.set_xlabel(r'Frequency \textbf[$\mathbf{kHz}$\textbf]') # plt.title(title_str_1) lplot.save_plt(plt, fname, sub_dir) plt.close() # 1}}} # cnt += 1