def plot_powerlaw_combined(data, data_inst, fig, units): from powerlaw import plot_pdf, Fit, pdf annotate_coord = (-.4, .95) ax1 = fig.add_subplot(n_graphs,n_data,data_inst) plot_pdf(data, ax=ax1, color='b', linewidth=2) fit = Fit(data, xmin=1, discrete=True) fit.power_law.plot_pdf(ax=ax1, linestyle=':', color='g') p = fit.power_law.pdf() fit = Fit(data, discrete=True) fit.power_law.plot_pdf(ax=ax1, linestyle='--', color='g') from pylab import setp setp( ax1.get_xticklabels(), visible=False) if data_inst==1: ax1.annotate("A", annotate_coord, xycoords="axes fraction", fontsize=14) ax1.set_ylabel(r"$p(X)$")# (10^n)") ax2 = fig.add_subplot(n_graphs,n_data,n_data+data_inst)#, sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g') fit.exponential.plot_pdf(ax=ax2, linestyle='--', color='r') fit.plot_pdf(ax=ax2, color='b', linewidth=2) ax2.set_ylim(ax1.get_ylim()) ax2.set_yticks(ax2.get_yticks()[::2]) ax2.set_xlim(ax1.get_xlim()) if data_inst==1: ax2.annotate("B", annotate_coord, xycoords="axes fraction", fontsize=14) ax2.set_xlabel(units)
def plot_basics(data, data_inst, fig, units): ''' This function is the main plotting function. Adapted from Newman's powerlaw package. ''' import pylab pylab.rcParams['xtick.major.pad'] = '8' pylab.rcParams['ytick.major.pad'] = '8' pylab.rcParams['font.sans-serif'] = 'Arial' from matplotlib import rc rc('font', family='sans-serif') rc('font', size=10.0) rc('text', usetex=False) from matplotlib.font_manager import FontProperties panel_label_font = FontProperties().copy() panel_label_font.set_weight("bold") panel_label_font.set_size(12.0) panel_label_font.set_family("sans-serif") n_data = 1 n_graphs = 4 from powerlaw import plot_pdf, Fit, pdf ax1 = fig.add_subplot(n_graphs, n_data, data_inst) x, y = pdf(data, linear_bins=True) ind = y > 0 y = y[ind] x = x[:-1] x = x[ind] ax1.scatter(x, y, color='r', s=.5, label='data') plot_pdf(data[data > 0], ax=ax1, color='b', linewidth=2, label='PDF') from pylab import setp setp(ax1.get_xticklabels(), visible=False) plt.legend(loc='bestloc') ax2 = fig.add_subplot(n_graphs, n_data, n_data + data_inst, sharex=ax1) plot_pdf(data[data > 0], ax=ax2, color='b', linewidth=2, label='PDF') fit = Fit(data, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle=':', color='g', label='w/o xmin') p = fit.power_law.pdf() ax2.set_xlim(ax1.get_xlim()) fit = Fit(data, discrete=True, xmin=3) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g', label='w xmin') from pylab import setp setp(ax2.get_xticklabels(), visible=False) plt.legend(loc='bestloc') ax3 = fig.add_subplot(n_graphs, n_data, n_data * 2 + data_inst) #, sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax3, linestyle='--', color='g', label='powerlaw') fit.exponential.plot_pdf(ax=ax3, linestyle='--', color='r', label='exp') fit.plot_pdf(ax=ax3, color='b', linewidth=2) ax3.set_ylim(ax2.get_ylim()) ax3.set_xlim(ax1.get_xlim()) plt.legend(loc='bestloc') ax3.set_xlabel(units)
def plot_basics(data, data_inst, fig, units): ''' This function is the main plotting function. Adapted from Newman's powerlaw package. ''' import pylab pylab.rcParams['xtick.major.pad']='8' pylab.rcParams['ytick.major.pad']='8' pylab.rcParams['font.sans-serif']='Arial' from matplotlib import rc rc('font', family='sans-serif') rc('font', size=10.0) rc('text', usetex=False) from matplotlib.font_manager import FontProperties panel_label_font = FontProperties().copy() panel_label_font.set_weight("bold") panel_label_font.set_size(12.0) panel_label_font.set_family("sans-serif") n_data = 1 n_graphs = 4 from powerlaw import plot_pdf, Fit, pdf ax1 = fig.add_subplot(n_graphs,n_data,data_inst) x, y = pdf(data, linear_bins=True) ind = y>0 y = y[ind] x = x[:-1] x = x[ind] ax1.scatter(x, y, color='r', s=.5, label='data') plot_pdf(data[data>0], ax=ax1, color='b', linewidth=2, label='PDF') from pylab import setp setp( ax1.get_xticklabels(), visible=False) plt.legend(loc = 'bestloc') ax2 = fig.add_subplot(n_graphs,n_data,n_data+data_inst, sharex=ax1) plot_pdf(data[data>0], ax=ax2, color='b', linewidth=2, label='PDF') fit = Fit(data, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle=':', color='g',label='w/o xmin') p = fit.power_law.pdf() ax2.set_xlim(ax1.get_xlim()) fit = Fit(data, discrete=True,xmin=3) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g', label='w xmin') from pylab import setp setp(ax2.get_xticklabels(), visible=False) plt.legend(loc = 'bestloc') ax3 = fig.add_subplot(n_graphs,n_data,n_data*2+data_inst)#, sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax3, linestyle='--', color='g',label='powerlaw') fit.exponential.plot_pdf(ax=ax3, linestyle='--', color='r',label='exp') fit.plot_pdf(ax=ax3, color='b', linewidth=2) ax3.set_ylim(ax2.get_ylim()) ax3.set_xlim(ax1.get_xlim()) plt.legend(loc = 'bestloc') ax3.set_xlabel(units)
def plot_basics(data, data_inst, fig, units): from powerlaw import plot_pdf, Fit, pdf annotate_coord = (-.4, .95) ax1 = fig.add_subplot(n_graphs,n_data,data_inst) x, y = pdf(data, linear_bins=True) ind = y>0 y = y[ind] x = x[:-1] x = x[ind] ax1.scatter(x, y, color='r', s=.5) plot_pdf(data[data>0], ax=ax1, color='b', linewidth=2) from pylab import setp setp( ax1.get_xticklabels(), visible=False) if data_inst==1: ax1.annotate("A", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) from mpl_toolkits.axes_grid.inset_locator import inset_axes ax1in = inset_axes(ax1, width = "30%", height = "30%", loc=3) ax1in.hist(data, normed=True, color='b') ax1in.set_xticks([]) ax1in.set_yticks([]) ax2 = fig.add_subplot(n_graphs,n_data,n_data+data_inst, sharex=ax1) plot_pdf(data, ax=ax2, color='b', linewidth=2) fit = Fit(data, xmin=1, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle=':', color='g') p = fit.power_law.pdf() ax2.set_xlim(ax1.get_xlim()) fit = Fit(data, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g') from pylab import setp setp( ax2.get_xticklabels(), visible=False) if data_inst==1: ax2.annotate("B", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax2.set_ylabel(u"p(X)")# (10^n)") ax3 = fig.add_subplot(n_graphs,n_data,n_data*2+data_inst)#, sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax3, linestyle='--', color='g') fit.exponential.plot_pdf(ax=ax3, linestyle='--', color='r') fit.plot_pdf(ax=ax3, color='b', linewidth=2) ax3.set_ylim(ax2.get_ylim()) ax3.set_xlim(ax1.get_xlim()) if data_inst==1: ax3.annotate("C", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax3.set_xlabel(units)
def plot_basics(data, data_inst, fig, units): from powerlaw import plot_pdf, Fit, pdf annotate_coord = (-.1, .95) # annotate_coord = (1.1, .95) ax1 = fig.add_subplot(n_graphs, n_data, data_inst, visible=False) x, y = pdf(data, linear_bins=True) ind = y > 0 y = y[ind] x = x[:-1] x = x[ind] ax1.scatter(x, y, color='r', s=.5) plot_pdf(data[data > 0], ax=ax1, color='b', linewidth=2) from pylab import setp setp(ax1.get_xticklabels(), visible=False) # ABC # if data_inst == 1: # ax1.annotate("A", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) # ax1.set_ylabel(u"p(X)") # from mpl_toolkits.axes_grid.inset_locator import inset_axes # ax1in = inset_axes(ax1, width="30%", height="30%", loc=3) # ax1in.hist(data, density=True, color='b') # ax1in.set_xticks([]) # ax1in.set_yticks([]) # ax1.set_xlabel(units) ax2 = fig.add_subplot(n_graphs, n_data, n_data + data_inst, sharex=ax1, visible=False) plot_pdf(data, ax=ax2, color='b', linewidth=2, label="pdf of data") fit = Fit(data, xmin=1, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle=':', color='g', label="power law fit") p = fit.power_law.pdf() ax2.set_xlim(ax1.get_xlim()) fit = Fit(data, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g', label="power law fit--opt xmin") from pylab import setp setp(ax2.get_xticklabels(), visible=True) # if data_inst == 1: ax2.annotate("B", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax2.set_ylabel(u"p(X)") # (10^n)") handles, labels = ax2.get_legend_handles_labels() ax2.legend(handles, labels, loc=3) ax2.set_xlabel(units) ax3 = fig.add_subplot(n_graphs, n_data, n_data * 2 + data_inst) # , sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax3, linestyle='--', color='g', label="power law fit\n(opt-min)") fit.exponential.plot_pdf(ax=ax3, linestyle='--', color='r', label="exponential fit\n(opt-min)") fit.plot_pdf(ax=ax3, color='b', linewidth=2, label="PDF\n(opt-min)") ax3.set_ylim(ax2.get_ylim()) ax3.set_xlim(ax1.get_xlim()) handles, labels = ax3.get_legend_handles_labels() ax3.legend(handles, labels, loc=3, fontsize=12) ax3.set_xlabel(units, fontsize=15) # if data_inst == 1: ax3.annotate("C", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax3.set_ylabel(u"p(X)", fontsize=15)
def plot_basics(data, data_inst, fig, units): ### Setup ### from powerlaw import plot_pdf, Fit, pdf import pylab pylab.rcParams['xtick.major.pad'] = '8' pylab.rcParams['ytick.major.pad'] = '8' #pylab.rcParams['font.sans-serif']='Arial' from matplotlib.font_manager import FontProperties panel_label_font = FontProperties().copy() panel_label_font.set_weight("bold") panel_label_font.set_size(30.0) panel_label_font.set_family("sans-serif") n_data = 2 n_graphs = 4 annotate_coord = (-.4, .95) ############# ax1 = fig.add_subplot(n_graphs, n_data, data_inst) x, y = pdf(data, linear_bins=True) ind = y > 0 y = y[ind] x = x[:-1] x = x[ind] ax1.scatter(x, y, color='r', s=.5) plot_pdf(data[data > 0], ax=ax1, color='b', linewidth=2) from pylab import setp setp(ax1.get_xticklabels(), visible=False) if data_inst == 1: ax1.annotate("A", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax2 = fig.add_subplot(n_graphs, n_data, n_data + data_inst, sharex=ax1) plot_pdf(data, ax=ax2, color='b', linewidth=2) fit = Fit(data, xmin=1, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g') _ = fit.power_law.pdf() ax2.set_xlim((1, max(x))) setp(ax2.get_xticklabels(), visible=False) if data_inst == 1: ax2.annotate("B", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax2.set_ylabel(u"p(X)") # (10^n)") ax3 = fig.add_subplot(n_graphs, n_data, n_data * 2 + data_inst) #, sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax3, linestyle='--', color='g') fit.exponential.plot_pdf(ax=ax3, linestyle='--', color='r') fit.lognormal.plot_pdf(ax=ax3, linestyle=':', color='r') fit.plot_pdf(ax=ax3, color='b', linewidth=2) ax3.set_ylim(ax2.get_ylim()) ax3.set_xlim(ax1.get_xlim()) if data_inst == 1: ax3.annotate("C", annotate_coord, xycoords="axes fraction", fontproperties=panel_label_font) ax3.set_xlabel(units)
def plot_basics(data, data_inst, fig, units): from powerlaw import plot_pdf, Fit, pdf annotate_coord = (-.4, .95) ax1 = fig.add_subplot(n_graphs,n_data,data_inst) plot_pdf(data[data>0], ax=ax1, linear_bins=True, color='r', linewidth=.5) x, y = pdf(data, linear_bins=True) ind = y>0 y = y[ind] x = x[:-1] x = x[ind] ax1.scatter(x, y, color='r', s=.5) plot_pdf(data[data>0], ax=ax1, color='b', linewidth=2) from pylab import setp setp( ax1.get_xticklabels(), visible=False) #ax1.set_xticks(ax1.get_xticks()[::2]) ax1.set_yticks(ax1.get_yticks()[::2]) locs,labels = yticks() #yticks(locs, map(lambda x: "%.0f" % x, log10(locs))) if data_inst==1: ax1.annotate("A", annotate_coord, xycoords="axes fraction", fontsize=14) from mpl_toolkits.axes_grid.inset_locator import inset_axes ax1in = inset_axes(ax1, width = "30%", height = "30%", loc=3) ax1in.hist(data, normed=True, color='b') ax1in.set_xticks([]) ax1in.set_yticks([]) ax2 = fig.add_subplot(n_graphs,n_data,n_data+data_inst, sharex=ax1) plot_pdf(data, ax=ax2, color='b', linewidth=2) fit = Fit(data, xmin=1, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle=':', color='g') p = fit.power_law.pdf() #ax2.set_ylim(min(p), max(p)) ax2.set_xlim(ax1.get_xlim()) fit = Fit(data, discrete=True) fit.power_law.plot_pdf(ax=ax2, linestyle='--', color='g') from pylab import setp setp( ax2.get_xticklabels(), visible=False) #ax2.set_xticks(ax2.get_xticks()[::2]) if ax2.get_ylim()[1] >1: ax2.set_ylim(ax2.get_ylim()[0], 1) ax2.set_yticks(ax2.get_yticks()[::2]) #locs,labels = yticks() #yticks(locs, map(lambda x: "%.0f" % x, log10(locs))) if data_inst==1: ax2.annotate("B", annotate_coord, xycoords="axes fraction", fontsize=14) ax2.set_ylabel(r"$p(X)$")# (10^n)") ax3 = fig.add_subplot(n_graphs,n_data,n_data*2+data_inst)#, sharex=ax1)#, sharey=ax2) fit.power_law.plot_pdf(ax=ax3, linestyle='--', color='g') fit.exponential.plot_pdf(ax=ax3, linestyle='--', color='r') fit.plot_pdf(ax=ax3, color='b', linewidth=2) #p = fit.power_law.pdf() ax3.set_ylim(ax2.get_ylim()) ax3.set_yticks(ax3.get_yticks()[::2]) ax3.set_xlim(ax1.get_xlim()) #locs,labels = yticks() #yticks(locs, map(lambda x: "%.0f" % x, log10(locs))) if data_inst==1: ax3.annotate("C", annotate_coord, xycoords="axes fraction", fontsize=14) #if ax2.get_xlim()!=ax3.get_xlim(): # zoom_effect01(ax2, ax3, ax3.get_xlim()[0], ax3.get_xlim()[1]) ax3.set_xlabel(units)