def plot_preset(preset_name, preset, save=False, close=True): plt.figure() plt.suptitle('Preset: {} (N = {})'.format(preset_name, preset.N)) plt.subplot(2, 1, 1) plt.ylabel('Phase histogram') phase_range = (0, 2.0 * math.pi) plt.xlim(phase_range[0], phase_range[1]) plt.hist(preset.phase, bins=50, range=phase_range) plt.subplot(2, 1, 2) plt.ylabel('Frequency histogram') freq_range = (np.percentile(preset.freq, 5), np.percentile(preset.freq, 95)) d = freq_range[1] - freq_range[0] freq_range = (freq_range[0] - 0.15*d, freq_range[1] + 0.15*d) plt.xlim(freq_range[0], freq_range[1]) plt.hist(preset.freq, bins=50, range=freq_range) if save: save_plot(preset_name, close=False) else: plt.show() if close: plt.close()
def plot_step(params): name = params['name'] #preset = params['preset'] step = params['step'] f_name = params['f_name'] dir_name = params['dir_name'] preset = load_preset_from_file(name) freq = preset.freq with open(f_name, 'r') as f: lines = f.readlines() step_, N, r, mean = (x for x in lines[0].split()) step_ = int(step_) assert (step_ == step) N = int(N) r = float(r) mean = float(mean) phases = [float(x) for x in lines[1].split()] vel = [float(x) for x in lines[2].split()] #print len(phases), len(vel) print(step) #for i in xrange(N): # pos = (phases[i], freq[i]) # print pos plt.figure() plt.suptitle('Step: ' + str(step)) plt.subplot(2, 1, 1) #py.axvline(95) #py.axvline(35) #plt.xlabel('Phase') plt.ylabel('Phase histogram') plt.hist(phases, bins=60, range=(0, 2.0 * math.pi)) plt.xlim(0, 2.0 * math.pi) plt.subplot(2, 1, 2) #plt.xlabel('Velocity') plt.ylabel('Velocity histogram') #range = (np.min(vel), np.max(vel)) range = (-30, 30) plt.hist(vel, bins=60, range=range) plt.xlim(range[0], range[1]) save_plot(os.path.join(dir_name, 'hist', str(step))) plt.figure() plt.title('Step: ' + str(step)) plt.xlabel('Phase') plt.ylabel('Intrinsic frequency') plt.xlim(0, 2.0 * math.pi) plt.ylim(-3, 3) plt.plot(phases, freq, marker='o', ls='') save_plot(os.path.join(dir_name, 'phase', str(step)))
def plot_step(params): name = params['name'] #preset = params['preset'] step = params['step'] f_name = params['f_name'] dir_name = params['dir_name'] preset = load_preset_from_file(name) freq = preset.freq with open(f_name, 'r') as f: lines = f.readlines() step_, N, r, mean = (x for x in lines[0].split()) step_ = int(step_) assert(step_ == step) N = int(N) r = float(r) mean = float(mean) phases = [float(x) for x in lines[1].split()] vel = [float(x) for x in lines[2].split()] #print len(phases), len(vel) print(step) #for i in xrange(N): # pos = (phases[i], freq[i]) # print pos plt.figure() plt.suptitle('Step: ' + str(step)) plt.subplot(2, 1, 1) #py.axvline(95) #py.axvline(35) #plt.xlabel('Phase') plt.ylabel('Phase histogram') plt.hist(phases, bins=60, range=(0, 2.0 * math.pi)) plt.xlim(0, 2.0 * math.pi) plt.subplot(2, 1, 2) #plt.xlabel('Velocity') plt.ylabel('Velocity histogram') #range = (np.min(vel), np.max(vel)) range = (-30, 30) plt.hist(vel, bins=60, range=range) plt.xlim(range[0], range[1]) save_plot(os.path.join(dir_name, 'hist', str(step))) plt.figure() plt.title('Step: ' + str(step)) plt.xlabel('Phase') plt.ylabel('Intrinsic frequency') plt.xlim(0, 2.0 * math.pi) plt.ylim(-3, 3) plt.plot(phases, freq, marker='o', ls='') save_plot(os.path.join(dir_name, 'phase', str(step)))
def tree_all(tree, plane='xy', feature='radial_distances', title='', diameter=True, treecol='b', xlims=None, ylims=None, **kwargs): '''Subplot with ph, barcode and tree ''' from tmd import utils as _utils from matplotlib.collections import LineCollection kwargs['output_path'] = kwargs.get('output_path', None) fig1, ax1 = _view.tree(tree, new_fig=True, subplot=221, plane='xy', title=title, treecolor=treecol, diameter=diameter) feat = getattr(tree, 'get_section_' + feature)() segs = tree.get_segments() def _seg_2d(seg): """2d coordinates required for the plotting of a segment""" horz = _utils.term_dict[plane[0]] vert = _utils.term_dict[plane[1]] horz1 = seg[0][horz] horz2 = seg[1][horz] vert1 = seg[0][vert] vert2 = seg[1][vert] return ((horz1, vert1), (horz2, vert2)) if plane in ['xy', 'yx', 'zx', 'xz', 'yz', 'zy']: ph = _tm.methods.get_persistence_diagram(tree, feature=feature) else: raise Exception('Plane value not recognised') bounds = max(max(ph)) fig1, ax2 = ph_diagram(ph, new_fig=False, subplot=222, color=treecol) fig1, ax3 = barcode(ph, new_fig=False, subplot=223, color=treecol) fig1, ax4 = ph_image(ph, new_fig=False, subplot=224, xlims=xlims, ylims=ylims) _cm.plt.tight_layout(True) if kwargs['output_path'] is not None: fig = _cm.save_plot(fig=ax1, **kwargs) return fig1, ax1
def plot_crit_k(preset_name, K_values, r_mean, save=True, close=True): plt.figure() plt.xlabel('k') plt.ylabel('r') plt.xlim(np.min(K_values), np.max(K_values)) plt.ylim(0, 1) plt.plot(K_values, r_mean) # TODO: plot theoretical value if save: save_plot(os.path.join('dump_' + preset_name, 'crit_k')) else: plt.show() if close: plt.close()
def gen_mean_and_r_plots(dir_name): with open(os.path.join(dir_name, 'r.txt')) as f: r = [float(x) for x in f.read().split()] plt.figure() plt.xlabel('Steps') plt.ylabel('Order parameter') plt.xlim(0, len(r)) plt.ylim(0, 1) plt.plot(range(0, len(r)), r) save_plot(os.path.join('dump_' + name, 'r')) with open(os.path.join(dir_name, 'mean.txt')) as f: mean = [float(x) for x in f.read().split()] plt.figure() plt.xlabel('Steps') plt.ylabel('Mean phase') plt.xlim(0, len(mean)) plt.ylim(0, 2.0 * math.pi) plt.plot(range(0, len(mean)), mean) save_plot(os.path.join('dump_' + name, 'mean')) with open(os.path.join(dir_name, 'mean_vel.txt')) as f: mean_vel = [float(x) for x in f.read().split()] plt.figure() plt.xlabel('Steps') plt.ylabel('Mean velocity') plt.xlim(0, len(mean_vel)) plt.plot(range(0, len(mean_vel)), mean_vel) save_plot(os.path.join('dump_' + name, 'mean_vel'))
def neu_all(neuron, plane='xy', feature='radial_distances', title='', diameter=True, treecol='b', xlims=None, ylims=None, neurite_type='basal', **kwargs): '''Subplot with ph, barcode and tree within spheres ''' from tmd import utils as _utils from matplotlib.collections import LineCollection kwargs['output_path'] = kwargs.get('output_path', None) fig1, ax1 = _view.neuron(neuron, new_fig=True, subplot=221, plane='xy', neurite_type=[neurite_type], title=title, treecolor=treecol, diameter=diameter) if plane in ['xy', 'yx', 'zx', 'xz', 'yz', 'zy']: ph = _tm.methods.get_ph_neuron(neuron, feature=feature, neurite_type=neurite_type) else: raise Exception('Plane value not recognised') bounds = max(max(ph)) fig1, ax2 = ph_diagram(ph, new_fig=False, subplot=222, color=treecol) fig1, ax3 = barcode(ph, new_fig=False, subplot=223, color=treecol) fig1, ax4 = ph_image(ph, new_fig=False, subplot=224, xlims=xlims, ylims=ylims) _cm.plt.tight_layout(True) if kwargs['output_path'] is not None: fig = _cm.save_plot(fig=ax1, **kwargs) return fig1, ax1
plt, ax, fig = common.get_pyplot_ax_fig() ax.grid(True, color='xkcd:light grey') ax.set_axisbelow(True) # ensure grid is below data lines = [] for (folder, lats) in values.items(): (color, label, marker) = common.get_color_label_marker( folder ) # this works with folder names due to how we determine this info... x = lats y = [(float(n + 1) / (len(lats) + 1)) for n in range(len(lats))] ax.plot(x, y, color=color, label=label) plt.legend(loc='upper right', handletextpad=0.3, borderaxespad=0, facecolor='white', framealpha=1, edgecolor='white') plt.yscale('log', basey=10, nonposy='mask') # Primorac et al. 2017, beyond 99.99th percentile NIC timestamp accuracy is not reliable ax.set_ylim(bottom=0.0001, top=1.03) # 1.03 so the top line doesn't get cut off ax.set_xlim(lat_min, lat_9999th) plt.xlabel('Latency (\u03BCs)') plt.ylabel('CCDF') common.save_plot(plt, name) print("Done! Plot is in ../plots/" + name + ".svg")