def hist_plot(ax, deg_dists, colors, graph_names, graph_ls): # Loop through all desired graphs for deg, col, lab, ls in zip(deg_dists, colors, graph_names, graph_ls): hist, plt_bins = np.histogram(deg, lin_bins, normed=True) # Correct x-coords to center them on histogram bins plt_bins_mid = plt_bins + np.diff(plt_bins)[0] * 0.5 ax.plot(plt_bins_mid[:-1], hist, ls=ls, lw=3, color=col, label=lab) # Set axis limits and ticks, and label subplots ax.set_xlim([0, 150]) #ax.set_ylim([0, .15]) ax.locator_params(axis='x', nbins=5) #a.locator_params(axis='y', nbins=5) # Set title ax.set_title('Degree Distributions') # Set xlabels ax.set_xlabel('Degree') ax.set_ylabel('P(k)') # Set all fontsizes and axis colors set_all_text_fontsizes(ax, FONT_SIZE)
def hist_plot(ax, deg_dists, colors, gammas, alphas, bins): for deg, col, g, alpha in zip(deg_dists, colors, gammas, alphas): hist, plt_bins = np.histogram(deg, bins, normed=True) ax.plot(plt_bins[:-1], hist, lw=2, color=col, label=str(g), alpha=alpha) # Set axis limits and ticks, and label subplots ax.set_xlim([0, 150]) #ax.set_ylim([0, .15]) ax.locator_params(axis='x', nbins=5) #a.locator_params(axis='y', nbins=5) ax.legend(loc='best', fontsize=ft_size - 6) # Set xlabels ax.set_xlabel('Degree') ax.set_ylabel('P(k)') # Set all fontsizes and axis colors set_all_text_fontsizes(ax, ft_size)
def hist_plot(ax, deg_dists, colors, graph_names, graph_ls): # Loop through all desired graphs for deg, col, lab, ls in zip(deg_dists, colors, graph_names, graph_ls): hist, plt_bins = np.histogram(deg, lin_bins, normed=True) # Correct x-coords to center them on histogram bins plt_bins_mid = plt_bins + np.diff(plt_bins)[0] * 0.5 ax.plot(plt_bins_mid[:-1], hist, ls=ls, lw=3, color=col, label=lab) # Set axis limits and ticks, and label subplots ax.set_xlim([0, 150]) ax.locator_params(axis='x', nbins=5) # Set title ax.set_title('Degree Distributions') # Set xlabels ax.set_xlabel('Degree') ax.set_ylabel('P(k)') # Set all fontsizes and axis colors set_all_text_fontsizes(ax, FONT_SIZE)
print('generating model...') G_pa, _, _ = pa(N=bc.num_brain_nodes, N_edges=bc.num_brain_edges_directed, L=np.inf) # cast both models to undirected graphs # plot preferential growth (L = np.inf) and pref attachment fig, ax = plt.subplots(1, 1, facecolor=FACE_COLOR, figsize=FIG_SIZE, tight_layout=True) colors = (COLORS['pref-attachment'], COLORS['pref-growth'], COLORS['pgpa'], COLORS['brain']) for G, color in zip((G_pa, G_pgpa_L_inf, G_pgpa, G_brain), colors): deg = nx.degree(G.to_undirected()).values() cc = nx.clustering(G.to_undirected()).values() ax.scatter(deg, cc, c=color, lw=0, alpha=ALPHA) ax.set_xlabel('Degree') ax.set_ylabel('Clustering\ncoefficient') ax.set_xlim(0, 150) ax.set_xticks((0, 50, 100, 150)) ax.set_ylim(0, 1) ax.set_yticks((0, 0.2, 0.4, 0.6, 0.8, 1)) ax.legend(('preferential attachment', 'preferential growth', 'PGPA', 'brain'), fontsize=FONT_SIZE) change_settings.set_all_text_fontsizes(ax, FONT_SIZE) plt.draw() plt.show(block=True)
fig, axs = plt.subplots(1, 2, figsize=cf.FIGSIZE_DIRECTED_MODELS, facecolor=FACECOLOR, tight_layout=True) # Plot clustering vs. degree scatter plots for ctr, ax in enumerate(axs.flatten()): deg = nx.degree(Gs[ctr].to_undirected()).values() cc = nx.clustering(Gs[ctr].to_undirected()).values() ax.scatter(deg, cc, s=cf.MARKERSIZE, c=colors[ctr], lw=cf.LW) # Set labels and limits for ax in axs: ax.set_xlabel('Degree') ax.set_xlim(cf.XLIMITS) ax.set_ylim(cf.YLIMITS) ax.set_xticks([0,125,250]) axs[0].set_ylabel('Clustering\ncoefficient') axs[0].set_title('Random\nattachment') axs[1].set_title('Proximal\nattachment') # Set all fontsizes and axis colors for ax in axs.flatten(): set_all_text_fontsizes(ax, cf.FONTSIZE) set_all_colors(ax, 'w') plt.draw() fig.savefig('/Users/rkp/Desktop/directed_clustering_vs_degree.png', transparent=True)
ax0.set_xlabel('Indegree') ax0.set_ylabel('Outdegree') ax0_histTop.set_title('In- vs. Outdegree', fontsize=FONTSIZE + 2, va='bottom') ax0.set_xlim(*cf.IN_OUT_SCATTER_XLIM) ax0.set_ylim(*cf.IN_OUT_SCATTER_YLIM) ax0.set_aspect('auto') ax0_histTop.set_ylabel('# nodes') ax0_histRight.set_xlabel('# nodes') ########################################################################## # Plot percent_indeg vs. degree (RIGHT SIDE) ax1.scatter(deg, percent_indeg, s=cf.MARKERSIZE, lw=0, c=MARKERCOLOR) ax1.set_xlabel('Total degree (in + out)') ax1.set_ylabel('Proportion in-degree') ax1.xaxis.set_major_locator(plt.MaxNLocator(4)) ax1.set_yticks(np.arange(0, 1.1, .2)) ax1.set_title('Proportion of Edges that are Incoming\nvs. Degree', fontsize=cf.FONTSIZE + 2, va='bottom') ax1.set_ylim([0., 1.05]) ########################################################################## # Set background color and text size for all spines/ticks for temp_ax in [ax0, ax0_histRight, ax0_histTop, ax1]: set_all_text_fontsizes(temp_ax, FONTSIZE) set_all_colors(temp_ax, cf.LABELCOLOR) #temp_ax.patch.set_facecolor(FACECOLOR) # Set color of plot area temp_ax.tick_params(width=cf.TICKSIZE) #fig.savefig('/Users/richpang/Desktop/brain_in_out.png', transparent=True) plt.show()
axs[0].plot(bincs, cts_mean, lw=2, color=COLORS['sgpa']) axs[0].fill_between(bincs, cts_mean - cts_std, cts_mean + cts_std, color=COLORS['sgpa'], alpha=0.5, zorder=2) axs[0].set_xlim(0, 150) axs[0].set_ylim(0, 0.04) axs[0].set_xticks(np.arange(0, 151, 30)) axs[0].set_yticks(np.linspace(0, 0.04, 5, endpoint=True)) axs[0].set_xlabel('Undirected Degree') axs[0].set_ylabel('Probability') brain_handle = axs[1].hist(degree_brain, bins=BINS, color=COLORS['brain'], normed=True) sgpa_handle = axs[1].plot(bincs, cts_mean, lw=2, color=COLORS['sgpa']) axs[1].fill_between(bincs, cts_mean - cts_std, cts_mean + cts_std, color=COLORS['sgpa'], alpha=0.5, zorder=2) axs[1].set_xlim(0, 150) axs[1].set_ylim(1e-4, 1e-1) axs[1].set_xticks(np.arange(0, 151, 30)) axs[1].set_xlabel('Undirected Degree') axs[1].set_ylabel('Log probability') axs[1].set_yscale('log') axs[1].legend([brain_handle[-1][0], sgpa_handle[0]], ['Connectome', 'SGPA']) [change_settings.set_all_text_fontsizes(ax, FONT_SIZE) for ax in axs] for ax, label in zip(axs, labels): ax.text(0.05, 0.95, label, fontsize=20, fontweight='bold', transform=ax.transAxes, ha='center', va='center') fig.savefig('fig6fs2.png', dpi=300) fig.savefig('fig6fs2.pdf', dpi=300)
axs[3].scatter(BA_degree, BA_clustering, color=BA_COLOR) axs[3].plot(x,np.exp(reg_BA[1])*x**reg_BA[0],'k',linestyle='--',lw=3) # Set axis limits and ticks, and label subplots for ax_idx, ax in enumerate(axs.flatten()): ax.set_xlim(0, DEG_MAX) ax.set_ylim(0, 1) ax.set_xticks(DEG_TICKS) ax.set_yticks(CC_TICKS) ax.text(.08, .87, labels[ax_idx], color='k', fontsize=FONT_SIZE, fontweight='bold', transform=ax.transAxes) ax.set_xlabel('Degree') set_all_text_fontsizes(ax, FONT_SIZE) set_all_colors(ax, 'k') # Set titles ax.set_title(graph_names[ax_idx], fontsize=FONT_SIZE) # Hide x ticklabels in top row & y ticklabels in right columns if ax_idx == 0: ax.set_ylabel('Clustering\ncoefficient') ax.text(0.5, 0.85, r'$\mathrm{R^{2}}$ = %.2f' % r_squared_vals[ax_idx], color='k', fontsize=FONT_SIZE - 2, transform=ax.transAxes) else: ax.text(0.725, 0.85, '%0.2f' % r_squared_vals[ax_idx],
right_main_ax.set_xlabel('Total degree (in + out)') right_main_ax.set_ylabel('Proportion in-degree') right_main_ax.text(1., 1.2, labels[1], fontsize=FONTSIZE + 2, fontweight='bold', transform=right_main_ax.transAxes, ha='right') right_main_ax.set_xlim([0., 150.]) right_main_ax.set_ylim([-0.025, 1.025]) right_main_ax.legend(loc=(-0.35, 1.12), prop={'size': 12}) for temp_ax in [ left_main_ax, right_main_ax, top_margin_ax, right_margin_ax ]: set_all_text_fontsizes(temp_ax, FONTSIZE) set_all_colors(temp_ax, cf.LABELCOLOR) temp_ax.tick_params(width=1.) fig.subplots_adjust(left=0.125, top=0.925, right=0.95, bottom=0.225) fig.savefig('fig5sf5{}{}.pdf'.format(*labels), dpi=300) fig.savefig('fig5sf5{}{}.png'.format(*labels), dpi=300) plt.show(block=False) r, p = stats.spearmanr(indeg_sg_total, outdeg_sg_total) print('r = {}'.format(r)) print('p = {}'.format(p))
right_main_ax.set_xlabel('Total degree (in + out)') right_main_ax.set_ylabel('Proportion in-degree') right_main_ax.xaxis.set_major_locator(plt.MaxNLocator(4)) right_main_ax.set_yticks(np.arange(0, 1.1, .25)) right_main_ax.set_ylim([0., 1.05]) right_main_ax.set_xlim([0, 120]) right_main_ax.set_xticks(np.arange(0, 151, 50)) right_main_ax.text(1., 1.2, 'b', fontsize=FONT_SIZE + 2, fontweight='bold', transform=right_main_ax.transAxes, ha='right') top_margin_ax.set_ylabel('$P(K_\mathrm{in}=k)$') right_margin_ax.set_xlabel('$P(K_\mathrm{out}=k)$') for temp_ax in [left_main_ax, right_main_ax, top_margin_ax, right_margin_ax, top_dummy_ax, right_dummy_ax]: set_all_text_fontsizes(temp_ax, FONT_SIZE) set_all_colors(temp_ax, cf.LABELCOLOR) top_lin_ticks = top_margin_ax.get_yticklabels() right_lin_ticks = right_margin_ax.get_xticklabels() top_log_ticks = top_dummy_ax.get_yticklabels() right_log_ticks = right_dummy_ax.get_xticklabels() for tick in top_lin_ticks+right_lin_ticks: tick.set_color('k') tick.set_fontsize(FONT_SIZE-2) for tick in top_log_ticks+right_log_ticks: tick.set_color('blue') tick.set_fontsize(FONT_SIZE-5)
ax.scatter(deg, clust, s=MARKER_SIZE, color=cols[ax_i]) ax.plot(x, np.exp(reg[ax_i][1]) * x ** reg[ax_i][0], 'k', linestyle='--', lw=2) # Setting other parameters ax.set_xlim(0, DEG_MAX) ax.set_ylim(0, 1) ax.set_aspect(DEG_MAX / 1.) ax.set_xticks(DEG_TICKS) ax.set_yticks(CC_TICKS) ax.set_title(graph_names[ax_i], fontsize=FONT_SIZE) ax.text(.1, .87, labels[ax_i], fontsize=FONT_SIZE-1, fontweight='bold', transform=ax.transAxes) ax.set_xlabel('Degree') set_all_text_fontsizes(ax, FONT_SIZE) set_all_colors(ax, 'k') # Hide x ticklabels in top row & y ticklabels in right columns if ax_i == 0: ax.set_ylabel('Clustering\ncoefficient') ax.text(0.4, 0.85, r'R$^2$ = %.2f' % r_squared_vals[ax_i], fontsize=FONT_SIZE - 2, transform=ax.transAxes) else: ax.text(0.725, 0.85, '%0.2f' % r_squared_vals[ax_i], fontsize=FONT_SIZE - 2, transform=ax.transAxes) ax.set_yticklabels('') fig.set_tight_layout({'pad': 1.02, 'w_pad': 0.4}) fig.savefig('fig1_cdef.png', dpi=300)
counts_nodal_efficiency_mean[key].argmax()], counts_nodal_efficiency_mean[key].max())) ax.set_xlim(X_LIM_EFFICIENCY) ax.set_ylim(Y_LIM_EFFICIENCY) ax.set_xlabel('Nodal efficiency') ax.set_ylabel('Number of nodes') lines = [h_line[0] for h_line in lines_temp] + [hist_connectome[-1][0]] axs[1].legend(lines, LABELS + ['Connectome'], fontsize=FONT_SIZE) texts = ('a', 'b') for ax, text in zip(axs, texts): change_settings.set_all_colors(ax, AX_COLOR) change_settings.set_all_text_fontsizes(ax, FONT_SIZE) ax.text(0.05, 0.95, text, fontsize=20, fontweight='bold', transform=ax.transAxes, ha='center', va='center') # add inset with power-law fit bar plot ax_inset = fig.add_axes(INSET_COORDINATES) gamma_means = [power_law_fits[key].mean() for key in PLOT_KEYS + ['brain']] gamma_stds = [power_law_fits[key].std() for key in PLOT_KEYS + ['brain']] gamma_median_r_squareds = [ np.median(fits_r_squared[key]) for key in PLOT_KEYS + ['brain']
right_main_ax.text(1., 1.2, 'b', fontsize=FONT_SIZE + 2, fontweight='bold', transform=right_main_ax.transAxes, ha='right') top_margin_ax.set_ylabel('$P(K_\mathrm{in}=k)$') right_margin_ax.set_xlabel('$P(K_\mathrm{out}=k)$') for temp_ax in [ left_main_ax, right_main_ax, top_margin_ax, right_margin_ax, top_dummy_ax, right_dummy_ax ]: set_all_text_fontsizes(temp_ax, FONT_SIZE) set_all_colors(temp_ax, cf.LABELCOLOR) top_lin_ticks = top_margin_ax.get_yticklabels() right_lin_ticks = right_margin_ax.get_xticklabels() top_log_ticks = top_dummy_ax.get_yticklabels() right_log_ticks = right_dummy_ax.get_xticklabels() for tick in top_lin_ticks + right_lin_ticks: tick.set_color('k') tick.set_fontsize(FONT_SIZE - 2) for tick in top_log_ticks + right_log_ticks: tick.set_color('blue') tick.set_fontsize(FONT_SIZE - 5)