Exemplo n.º 1
0
def plot_png(xpbc, ypbc, nbpc, ncells, lx, ly, frame):
    """ plot the frame as colored png image"""

    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    patches = []
    k = 0
    for n in range(ncells):
        r = np.vstack((xpbc[k:k + nbpc[n]] / 0.5, ypbc[k:k + nbpc[n]] / 0.5)).T
        k += nbpc[n]
        polygon = Polygon(r, True)
        patches.append(polygon)

    p = PatchCollection(patches, facecolor='black', alpha=1.0)

    ax0.add_collection(p)
    ax0.autoscale_view()

    ax0.scatter(xpbc / 0.5, ypbc / 0.5, s=1.0, c='black', alpha=1.0)

    ax0.axis('equal')
    ax0.set_xlim((-10, lx / 0.5 + 10))
    ax0.set_ylim((-10, ly / 0.5 + 10))
    ax0.axis('off')

    savepath = "area_polygons_" + str(frame) + ".png"
    plt.savefig(savepath, dpi=300, bbox_inches='tight', pad_inches=0.0)
    plt.clf()
    plt.close(fig)

    return savepath
Exemplo n.º 2
0
def plot_data(x, data, param_choice, sims, savebase, savefolder):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0                          # Length of one subplot square box
    ax_b = 0.0                            # Beginning/offset of the subplot in the box
    ax_sep = 0.0                          # Separation length between two subplots
    total_subplots_in_x = 1               # Total number of subplots    
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x) 
    ax0 = subp.addSubplot()
                          
    ### plot 

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x) 
    ax0 = subp.addSubplot()
    
    for p in data.keys():
        
        sim = sims[p]       # simulation information
        y = data[p]         # analysis data
    
        label = r'$\epsilon=$' + str(sim.eps) + '$,f_{m}=$' + str(sim.fp) + \
            '$,\kappa_{A}=$' + str(sim.areak) + '$,\kappa_{B}=$' + str(sim.kappa)
        line0 = ax0.semilogx(x/sim.tau_D, y, \
                         linewidth=2.0, label=label)
    
    ### labels
        
    ax0.set_xlabel(r"$\Delta t/\tau_{D}$", fontsize=30)
    ax0.set_ylabel(r"$F_{s}(q)$", fontsize=30)

    ### limits

    ax0.set_xlim((1e-1, 5e2))
    ax0.set_ylim((-0.1, 1.0))
    
    ### ticks
    
    ax0.xaxis.set_ticks([1e-1, 1e0, 1e1, 1e2, 5e2])
    ax0.yaxis.set_ticks([0, 0.2, 0.4, 0.6, 0.8, 1.0])
    ax0.tick_params(axis='both', which='major', labelsize=30)
    
    ### legend

    ax0.legend(bbox_to_anchor=(0.15, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)
    
    ### save

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)  
    
    savepath1 = base + savefolder + "_transition_per_" + param_choice + ".png"
    savepath2 = base + savefolder + "_transition_per_" + param_choice + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)        
    fig.clf()                          
        
    return
Exemplo n.º 3
0
def plot_frames(wor, beads, cells, sim, ti, tf, savebase, save_eps):
    """ plot frames within the specified time window"""

    ### normalize variables for plotting purposes

    lx = sim.lx / sim.r_avg
    ly = sim.ly / sim.r_avg

    ### vorticity information

    steps, xbins, ybins, wx, wy, w, vx, vy = wor
    nwbins = max(xbins) + 1
    xlin = np.linspace(0., lx, nwbins)
    ylin = np.linspace(0., ly, nwbins)
    xgrid, ygrid = np.meshgrid(xlin, ylin)

    ### set general plot properties

    savebase += 'eps_' + str(sim.eps) + '_fp_' + str(sim.fp) + \
        '_areak_' + str(sim.areak) + '/'
    os.system("mkdir -p " + savebase)
    quant_steps = 2056

    # limits
    full_box_downlim = -2
    full_box_uplim = lx + 2
    full_box_ticks = [0, 35, 70, 105, 135]

    half_box_downlim = 43
    half_box_uplim = 92
    half_box_ticks = [45, 90]

    num_ticks = 5

    ax_len = 2.2  # Length of one subplot square box
    ax_b = 0.01  # Beginning/offset of the subplot in the box
    ax_sep = 0.15  # Separation length between two subplots
    total_subplots_in_x = 2  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    multi = True
    ax1 = subp.addSubplot(multi)
    ax3 = subp.addSubplot(multi)
    ax0 = subp.addSubplot(multi)
    ax2 = subp.addSubplot(multi)

    ### set subplot properties

    nslices = sim.ncells
    #    nslices = 100                          # Number of slices to take in the y dir
    norm_ax0 = mpl.colors.Normalize(vmin=0, vmax=nslices)
    #    vertical_pos_colors_per_bead = cell2bead_vertical_pos(beads, cells, sim, nslices, ti)
    #    cmap_ax1 = sns.dark_palette((260, 75, 60), n_colors=nslices, input="husl", as_cmap=True)
    #    cmap_ax1 = sns.diverging_palette(255, 133, l=60, n=nslices, center="dark", as_cmap=True)
    cmap_ax0 = plt.cm.get_cmap('jet', quant_steps)
    #norm_ax3 = MidPointNorm(midpoint=0)

    ### plot the frames

    comx = deque()
    comy = deque()
    ntrace = 6
    delta = 6

    if tf + delta > sim.nsteps:
        tf -= delta

    for step in range(ti, tf):

        time = step * sim.dt
        print 'Step / Total : ', step, tf

        ### normalize variables for plotting purposes

        beads.xi[step, 0, :] /= sim.r_avg
        beads.xi[step, 1, :] /= sim.r_avg
        cells.xi[step, 0, :] /= sim.r_avg
        cells.xi[step, 1, :] /= sim.r_avg

        ### calculate the displacement magnitudes

        dx, dy, dr = calc_displacement_magnitudes(cells, step, delta, sim)
        dr /= sim.r_avg
        norm_ax1 = mpl.colors.Normalize(vmin=min(dr), vmax=max(dr))

        ### prepare for streamline plot

        #        ndim = sim.ncells/10
        #        pts = np.vstack((cells.xi[step, 0, :], cells.xi[step, 1, :])).T
        #        vals = np.vstack((dx, dy)).T
        #        xli = np.linspace(cells.xi[step, 0, :].min(), cells.xi[step, 0, :].max(), ndim)
        #        yli = np.linspace(cells.xi[step, 1, :].min(), cells.xi[step, 1, :].max(), ndim)
        #        ipts = np.vstack(a.ravel() for a in np.meshgrid(yli, xli)[::-1]).T
        #        ivals = interpolate.griddata(pts, vals, ipts, method='cubic')
        #        uli, vli = ivals.T
        #        uli.shape = vli.shape = (ndim, ndim)

        ### keep the center of mass trajectory

        comx.append(cells.xi[step, 0, :])
        comy.append(cells.xi[step, 1, :])

        if step > ti + ntrace:
            comx.popleft()
            comy.popleft()

        ### get the vorticity information

        ws = w[steps == step]
        #        wxs = wx[steps==step]
        #        wys = wy[steps==step]
        #        wmean = np.mean(np.sqrt(wxs**2 + wys**2))
        wmean = np.mean(np.abs(ws))
        wn = np.zeros((nwbins, nwbins), dtype=np.float32)
        for xi, yi in zip(xbins, ybins):
            wn[xi, yi] = ws[xi * nwbins + yi]
        wn /= wmean
        #norm_ax3 = mpl.colors.Normalize(vmin=min(wn), vmax=max(wn))

        ### get the velocity information

        vxs = vx[steps == step]
        vys = vy[steps == step]
        vmean = np.mean(np.sqrt(vxs**2 + vys**2))
        vn = np.zeros((nwbins, nwbins), dtype=np.float32)
        vxg = np.zeros((nwbins, nwbins), dtype=np.float32)
        vyg = np.zeros((nwbins, nwbins), dtype=np.float32)
        for xi, yi in zip(xbins, ybins):
            vn[xi, yi] = np.sqrt(vxs[xi * nwbins + yi]**2 +
                                 vys[xi * nwbins + yi]**2)
            vxg[xi, yi] = vxs[xi * nwbins + yi]
            vyg[xi, yi] = vys[xi * nwbins + yi]
        vn /= vmean

        ### plot

        subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b,
                                   total_subplots_in_x)
        ax1 = subp.addSubplot(multi)
        ax3 = subp.addSubplot(multi)
        ax0 = subp.addSubplot(multi)
        ax2 = subp.addSubplot(multi)

        text = r"$t/\tau_{D}$ = " + "{0:.2f}".format( time/sim.tau_D) + \
            r", $t/\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A)

        ### AX0

        line0 = ax0.scatter(beads.xi[step, 0, :], beads.xi[step, 1, :], s=4.0, \
                            c=beads.cid, \
                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=1.0, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        ax0.axis('scaled')

        ### labels

        #ax0.set_xlabel(r"$x/R$", fontsize=40)
        ax0.set_ylabel(r"$y/R$", fontsize=40)

        ### limits

        ax0.set_xlim((full_box_downlim, full_box_uplim))
        ax0.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax0.xaxis.set_ticks(full_box_ticks)
        ax0.yaxis.set_ticks(full_box_ticks)
        plt.setp(ax0.get_xticklabels(), visible=False)
        ax0.tick_params(axis='both', which='major', labelsize=40)

        ### AX1

        #        line1 = ax1.scatter(cells.xi[step, 0, :], cells.xi[step, 1, :], s=6.0, \
        #                            c=np.arange(nslices), \
        #                            #c=dr,
        #                            cmap=cmap_ax0, \
        #                            edgecolors='None', alpha=1.0, vmin=0, vmax=nslices, \
        #                            norm=norm_ax0, rasterized=True)
        #
        #        line2 = ax1.scatter(list(comx), list(comy), s=5.0, \
        #                            c=np.ones(np.shape(list(comx)))*np.arange(nslices), \
        #                            #c=np.ones(np.shape(list(comx)))*dr,
        #                            cmap=cmap_ax0, \
        #                            edgecolors='None', alpha=0.5, vmin=0, vmax=nslices, \
        #                            norm=norm_ax0, rasterized=True)
        #
        #        ax1.axis('scaled')
        #
        #        ### labels
        #
        #        ax1.set_xlabel(r"$x/R$", fontsize=40)
        #        ax1.set_ylabel(r"$y/R$", fontsize=40)
        #
        #        ### limits
        #
        #        ax1.set_xlim((full_box_downlim, full_box_uplim))
        #        ax1.set_ylim((full_box_downlim, full_box_uplim))
        #
        #        ### ticks
        #
        #        ax1.xaxis.set_ticks(full_box_ticks)
        #        ax1.yaxis.set_ticks(full_box_ticks)
        #        #plt.setp(ax1.get_yticklabels(),visible=False)
        #        ax1.tick_params(axis='both', which='major', labelsize=40)

        #line1 = ax1.pcolor(xgrid, ygrid, vn.transpose(), cmap=cmap_ax0)
        line1 = ax1.contourf(xgrid, ygrid, vn.transpose(), cmap=cmap_ax0)

        line2 = ax1.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   dx, dy, \
                   #dr, cmap=cmap_ax0, norm=norm_ax1, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=1.0)
        #        line7 = ax3.streamplot(xli, yli, \
        #                   uli, vli, \
        #                   linewidth=1.0, density=2, arrowstyle='->', arrowsize=1.5)
        #dr, cmap=cmap_ax0, norm=norm_ax1)

        ax1.axis('scaled')

        ### labels

        ax1.set_xlabel(r"$x/R$", fontsize=40)
        ax1.set_ylabel(r"$y/R$", fontsize=40)

        ### limits

        ax1.set_xlim((full_box_downlim, full_box_uplim))
        ax1.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax1.xaxis.set_ticks(full_box_ticks)
        ax1.yaxis.set_ticks(full_box_ticks)
        #plt.setp(ax1.get_yticklabels(),visible=False)
        ax1.tick_params(axis='both', which='major', labelsize=40)

        ### AX2

        line3 = ax2.scatter(cells.xi[step, 0, :], cells.xi[step, 1, :], s=5.0, \
                            c=dr,
                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=0.8, vmin=min(dr), vmax=max(dr), \
                            norm=norm_ax1, rasterized=True)

        line4 = ax2.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   np.cos(cells.pol[step]), np.sin(cells.pol[step]), \
                   #dr, cmap=cmap_ax0, norm=norm_ax1, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=1.0)

        line5 = ax2.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   dx, dy, \
                   dr, cmap=cmap_ax0, norm=norm_ax1, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=1.0)

        #        line8 = ax2.streamplot(xli, yli, \
        #                   uli, vli, \
        #                   linewidth=1.0, density=2, arrowstyle='->', arrowsize=1.5)

        ax2.axis('scaled')

        cax2 = plt.colorbar(line5, ax=ax2)
        #plt.colorbar(line5, cax=cax3, ticks=[])
        #cax3.set_yticks([0, 0.8])
        #cax3.set_yticklabels(['0', '0.7'])
        cax2.ax.tick_params(labelsize=40)
        cax2.ax.set_title(r"$|d_{r}|/R$", fontsize=40)

        ### labels

        #ax2.set_xlabel(r"$x/R$", fontsize=40)

        ### limits

        ax2.set_xlim((full_box_downlim, full_box_uplim))
        ax2.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        #ax2.xaxis.set_ticks(full_box_ticks)
        ax2.xaxis.set_ticks(full_box_ticks)
        ax2.yaxis.set_ticks(full_box_ticks)
        plt.setp(ax2.get_xticklabels(), visible=False)
        plt.setp(ax2.get_yticklabels(), visible=False)
        ax2.tick_params(axis='both', which='major', labelsize=40)

        ### AX3

        #line6 = ax3.pcolor(xgrid, ygrid, wn.transpose(), cmap=cmap_ax0)
        #line6 = ax3.contourf(xgrid, ygrid, wn.transpose(), cmap=cmap_ax0, norm=norm_ax3)
        line6 = ax3.contourf(xgrid, ygrid, wn.transpose(), cmap=cmap_ax0)

        line7 = ax3.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   dx, dy, \
                   #dr, cmap=cmap_ax0, norm=norm_ax1, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=1.0)
        line7 = ax3.streamplot(xgrid, ygrid, \
                   vxg, vyg, \
                   linewidth=1.0, density=2, arrowstyle='->', arrowsize=1.5)
        #dr, cmap=cmap_ax0, norm=norm_ax1)

        ax3.axis('scaled')

        cax3 = plt.colorbar(line6, ax=ax3)
        #plt.colorbar(line5, cax=cax3, ticks=[])
        #cax3.set_yticks([0, 0.8])
        #cax3.set_yticklabels(['0', '0.7'])
        cax3.ax.tick_params(labelsize=40)
        cax3.ax.set_title(r"$\omega/<|\omega|>$", fontsize=40)

        ### labels

        ax3.set_xlabel(r"$x/R$", fontsize=40)

        ### limits

        ax3.set_xlim((full_box_downlim, full_box_uplim))
        ax3.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax3.xaxis.set_ticks(full_box_ticks)
        ax3.yaxis.set_ticks(full_box_ticks)
        plt.setp(ax3.get_yticklabels(), visible=False)
        ax3.tick_params(axis='both', which='major', labelsize=40)

        ### text

        plt.figtext(subp.xbeg - 0.9 * ax_sep,
                    subp.ybeg + ax_len + 0.1 * ax_sep,
                    text,
                    fontsize=40)

        ### save

        savepath1 = savebase + "frame-" + "{0:05d}".format(int(step)) + ".png"
        if save_eps:
            savepath2 = savebase + "frame-" + "{0:05d}".format(
                int(step)) + ".eps"

        plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
        if save_eps:
            plt.savefig(savepath2,
                        dpi=300,
                        bbox_inches='tight',
                        pad_inches=0.08)
        fig.clf()

    return
def plot_data(x, data, param_choice, sims, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### save properties

    name, pname = misc_tools.gen_save_props(param_choice, sims[data.keys()[0]])
    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    base = savebase + savefolder + '/' + name + '/'
    os.system("mkdir -p " + base)

    ### plot

    for a in data.keys():

        sim = sims[a]  # simulation information
        y = data[a]  # analysis data

        label = '$\\epsilon=$' + str(sim.eps) + \
            '$,f=$' + str(sim.fp) + '$,\\kappa_{A}=$' + str(sim.areak) + \
            '$,\\kappa=$' + str(sim.kappa)
        line0 = ax0.plot(x/sim.r_avg, y, \
                         linewidth=2.0, label=label)

    ### title

#    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
#        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

### labels

    ax0.set_xlabel("$r/R$", fontsize=40)
    ax0.set_ylabel("$g(r)$", fontsize=40)

    ### limits

    ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    ax0.legend(bbox_to_anchor=(1.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)

    savepath1 = base + savefolder + "_per_" + pname + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_per_" + name + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
Exemplo n.º 5
0
def plot_data(x, y, sim, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    xcut = x[70:]
    ycut = y[70:]

    label = '$\\epsilon=$' + str(sim.eps) + '$,f=$' + str(sim.fp) \
        + '$,\\kappa_{A}=$' + str(sim.areak)
    line0 = ax0.loglog(xcut/sim.tau_D, ycut/sim.r_avg**2, \
                     linewidth=2.0, label=label)

    line1 = ax0.loglog(xcut/sim.tau_D, xcut/sim.tau_D, \
                     linewidth=1.0, label=label)
    line2 = ax0.loglog(xcut/sim.tau_D, (xcut/sim.tau_D)**2, '--', \
                     linewidth=1.0, label=label)

    #    print "Linear x = ", xcut
    #    print "Linear y = ", ycut
    #    s = interpolate.UnivariateSpline(xcut, ycut)
    #    xnew = np.linspace(np.min(xcut), np.max(xcut), num=100*len(xcut))
    #    #xnew = np.logspace(np.min(xcut), np.max(xcut), num=10*len(xcut), base=10.0)
    #    ynew = s(xnew)
    #    print "Smooth splined y = ", ynew
    #    intp = interpolate.interp1d(xnew, ynew)
    #    ynew = intp(xnew)
    #    print "Interpolated y = ", ynew
    #
    #    line1 = ax0.loglog(xnew/sim.tau_D, ynew/sim.r_avg**2, \
    #                     linewidth=2.0, label=label)
    #    line2 = ax0.loglog(xnew/sim.tau_D, (xnew/sim.tau_D)**2, \
    #                     linewidth=1.0, label=label)
    #    line3 = ax0.loglog(xnew/sim.tau_D, xnew/sim.tau_D, '--',\
    #                     linewidth=1.0, label=label)
    #
    #    xcut = np.log10(xcut)
    #    ycut = np.log10(ycut)
    #    print (ycut[-1]-ycut[0])/(xcut[-1]-xcut[0])

    ### title

    #    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
    #        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

    ### labels

    ax0.set_xlabel("$t/\\tau_{D}$", fontsize=40)
    ax0.set_ylabel("$\\Delta r^{2}/R^{2}$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    #    ax0.legend(bbox_to_anchor=(1.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
    #        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    savepath1 = base + savefolder + "_eps_" + str(sim.eps) + "_fp_" + str(sim.fp) + \
        '_areak_' + str(sim.areak) + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_eps_" + str(sim.eps) + "_fp_" + str(sim.fp) + \
            '_areak_' + str(sim.areak) + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
def plot_data(x, data, param_choice, sims, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### save properties

    name, pname = misc_tools.gen_save_props(param_choice, sims[data.keys()[0]])
    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    base = savebase + savefolder + '/' + name + '/'
    os.system("mkdir -p " + base)

    ### plot

    keys = np.sort(data.keys())

    for p in keys:

        sim = sims[p]  # simulation information
        y = data[p]  # analysis data

        ### calculate the histogram

        yh, xh = np.histogram(y, bins=50, normed=True)
        xh = (xh[1:] + xh[:-1]) / 2.

        label = '$\\epsilon=$' + str(sim.eps) + \
            '$,f=$' + str(sim.fp) + '$,\\kappa_{A}=$' + str(sim.areak) + \
            '$,\\kappa=$' + str(sim.kappa)
        line0 = ax0.plot(xh, yh, \
                         linewidth=2.0, label=label)

        ### check normalization of the probability distribution

        print np.sum(np.diff(xh) * yh[:-1])

    ### title

#    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
#        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

### labels

#    ax0.set_xlabel(r"$\phi$", fontsize=40)
#    ax0.set_ylabel(r"$P(\phi)$", fontsize=40)
    ax0.set_xlabel(r"$\rho\sigma^2$", fontsize=40)
    ax0.set_ylabel(r"$P(\rho\sigma^2)$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    ax0.legend(bbox_to_anchor=(0.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)

    savepath1 = base + savefolder + "_per_" + pname + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_per_" + pname + ".pdf"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
Exemplo n.º 7
0
def plot_data(x, y, sim, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter"""

    ### set normalization parameter

    knorm = np.pi / sim.r_avg

    ### pick out the relevant portion of the data
    xd = 2. * np.pi / ((sim.lx - 4) / 2.)
    dc = np.argmin(np.abs(x - xd))
    xu = 2. * np.pi / (2. * sim.r_avg + 4)
    uc = np.argmin(np.abs(x - xu))
    print dc, uc
    dcf = 54
    ucf = 260
    dc = 0
    uc = len(x) - 55
    print dc, uc

    ### normalization and appropriate data range selection

    xnf = x[dcf:ucf] / knorm
    ynf = y[dcf:ucf] / x[dcf:ucf]
    xn = x[dc:uc] / knorm
    yn = y[dc:uc] / x[dc:uc]

    ### curve fitting

    popt, pcov = curve_fit(five_thirds, xnf, ynf)
    yfit = five_thirds(xnf, popt[0])
    print popt[0]

    ### set general plot properties

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    label = '$\\epsilon=$' + str(sim.eps) + '$,f=$' + str(
        sim.fp) + '$,\\kappa_{A}=$' + str(sim.areak)
    line0 = ax0.loglog(xn, yn, \
                     linewidth=2.0, label=label)

    ax0.axvline(2 * np.pi / (sim.lx * knorm / 2.), color='black')
    ax0.axvline(2 * np.pi / (sim.r_avg * 2. * knorm))

    line1 = ax0.loglog(xnf, yfit, '--', \
                     linewidth=2.0, label=label, color='red')

    #    line1 = ax0.loglog(xn, xn**-5./3., '--', \
    #                     linewidth=2.0, label=label)

    #    line0 = ax0.loglog(x[:cutp]/knorm, (x[:cutp]/knorm)**-8./3., '--', \
    #                     linewidth=2.0, label=label)
    ### title

    #    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
    #        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

    ### labels

    ax0.set_xlabel("$q/q_{2R}$", fontsize=40)
    ax0.set_ylabel("$E_{q}$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    #    ax0.legend(bbox_to_anchor=(1.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
    #        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    savepath1 = base + savefolder + "_eps_" + str(sim.eps) + "_fp_" + str(sim.fp) + \
        '_areak_' + str(sim.areak) + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_eps_" + str(sim.eps) + "_fp_" + str(sim.fp) + \
            '_areak_' + str(sim.areak) + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
Exemplo n.º 8
0
def plot_data(x, data, param_choice, sims, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### save properties

    name, pname, xlab, lab = \
        misc_tools.gen_save_props(param_choice, sims[data.keys()[0]])
    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    base = savebase + savefolder + '/' + name + '/'
    os.system("mkdir -p " + base)

    ### plot

    keys = np.sort(data.keys())
    y = np.zeros((len(keys)), dtype=np.float32)

    for j, p in enumerate(keys):

        sim = sims[p]  # simulation information
        y[j] = data[p]  # analysis data

    line0 = ax0.scatter(x, y, label=lab, s=80)
    line1 = ax0.plot(x, y, '--', label='_nolegend_')
    ax0.set_xscale('log')

    ### title

    #    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
    #        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

    ### labels

    ax0.set_xlabel(xlab, fontsize=40)
    ax0.set_ylabel(r"$\langle \Delta A \rangle/\sigma^2$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    ax0.legend(bbox_to_anchor=(0.3, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)

    savepath1 = base + savefolder + "_per_" + pname + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_per_" + pname + ".pdf"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
Exemplo n.º 9
0
def plot_data(x, data, param_choice, sims, savebase, savefolder):
    """ plot the data as a function of the chosen parameter"""

    ### set normalization parameter

    knorm = np.pi / sims[data.keys()[0]].r_avg

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    xd = 2. * np.pi / ((sims[data.keys()[0]].lx - 4) / 2.)
    dc = np.argmin(np.abs(x - xd))
    xu = 2. * np.pi / (2. * sims[data.keys()[0]].r_avg + 4)
    uc = np.argmin(np.abs(x - xu))
    print dc, uc
    dc = 54
    uc = 260
    #    dc = 0
    #    uc = len(x)
    print dc, uc

    for p in data.keys():

        sim = sims[p]  # simulation information
        y = data[p]  # analysis data

        ### normalization and appropriate data range selection

        xn = x[dc:uc] / knorm
        yn = y[dc:uc] / x[dc:uc]

        ### curve fitting

        popt, pcov = curve_fit(power_law, xn, yn)
        yfit = power_law(xn, popt[0], popt[1])
        print "key = ", p, ", fit param = ", popt[1]

        popt, pcov = curve_fit(five_thirds, xn, yn)
        yf_five_thirds = five_thirds(xn, popt[0])

        popt, pcov = curve_fit(thirds, xn, yn)
        yf_thirds = thirds(xn, popt[0])

        label = r'$\epsilon=$' + str(sim.eps) + '$,f_{m}=$' + str(sim.fp) + \
            '$,\kappa_{A}=$' + str(sim.areak)

        line0 = ax0.loglog(xn, yn, \
                         linewidth=2.0, label=label)
        #        ax0.loglog(xn, yfit, '--', \
        #                   linewidth=1.0, label='_nolegend_', color='black')
        ax0.loglog(xn, yf_five_thirds, '--', \
                   linewidth=1.0, label='_nolegend_', color='gray')
#        ax0.loglog(xn, yf_thirds, '--', \
#                   linewidth=1.0, label='_nolegend_', color='gray')

    ax0.axvline(2 * np.pi / (sim.lx * knorm / 2.))
    ax0.axvline(2 * np.pi / (sim.r_avg * 2. * knorm))
    #    ax0.loglog(np.ones_like(yn)*2*np.pi/(sim.lx*knorm/2.), yn, '--', \
    #               label='_nolegend_', linewidth=1.0, color='k')
    #    ax0.loglog(np.ones_like(yn)*2*np.pi/(sim.r_avg*2.*knorm), yn, '--', \
    #               label='_nolegend_', linewidth=1.0, color='k')

    ### labels

    ax0.set_xlabel(r"$q/q_{2R}$", fontsize=30)
    ax0.set_ylabel(r"$E(q)$", fontsize=30)

    ### limits

    ax0.set_xlim((0.03, 1.0))
    #    ax0.set_ylim((0.0, 1.9))

    ### ticks

    #    ax0.xaxis.set_ticks([0, 10, 20])
    ax0.yaxis.set_ticks([1e-5, 1e-3, 1e-1, 1e1])
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    ax0.legend(bbox_to_anchor=(0.35, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)

    savepath1 = base + savefolder + "_transition_per_" + param_choice + ".png"
    savepath2 = base + savefolder + "_transition_per_" + param_choice + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
Exemplo n.º 10
0
def plot_traj(x, sim, ti, tf, savebase, savefolder, save_eps):
    """ plot trajectory within the specified time window"""

    ### normalize variables for plotting purposes

    x /= sim.bl
    lx = sim.lx / sim.bl
    ly = sim.ly / sim.bl

    ### set general plot properties

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    downlim = -2
    uplim = lx + 2
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    label = '$\\phi=$' + str(sim.density) + '$,k_{m}=$' + str(sim.km)
    line0 = ax0.plot(x[ti:tf, 0, :], x[ti:tf, 1, :], \
                     linewidth=2.0, label=label)

    ax0.axis('scaled')

    ### title

    #    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
    #        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

    ### labels

    ax0.set_xlabel("$x/r_{0}$", fontsize=40)
    ax0.set_ylabel("$y/r_{0}$", fontsize=40)

    ### limits

    #ax0.set_xlim((downlim, uplim))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### save

    savepath1 = base + savefolder + "_density_" + str(sim.density) + "_kappa_" + str(sim.kappa) + \
        "_km_" + str(sim.km) + '_panti_' + str(sim.pa) + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_density_" + str(sim.density) + "_kappa_" + str(sim.kappa) + \
        "_km_" + str(sim.km) + '_panti_' + str(sim.pa) + ".eps"
    plt.savefig(savepath1, dpi=200, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=200, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
Exemplo n.º 11
0
def plot_frames(beads, cells, sim, ti, tf, savebase, save_eps):
    """ plot frames within the specified time window"""

    ### normalize variables for plotting purposes

    lx = sim.lx / sim.r_avg
    ly = sim.ly / sim.r_avg

    ### set general plot properties

    savebase += 'eps_' + str(sim.eps) + '_fp_' + str(sim.fp) + \
        '_areak_' + str(sim.areak) + '_kappa_' + str(sim.kappa) + '/'
    os.system("mkdir -p " + savebase)
    quant_steps = 2056

    # limits
    full_box_downlim = -2
    full_box_uplim = lx + 2
    full_box_ticks = [0, 35, 70, 105, 135]

    half_box_downlim = 43
    half_box_uplim = 92
    half_box_ticks = [45, 90]

    num_ticks = 5

    ax_len = 2.0  # Length of one subplot square box
    ax_b = 0.05  # Beginning/offset of the subplot in the box
    ax_sep = -0.4  # Separation length between two subplots
    total_subplots_in_x = 3  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()
    ax1 = subp.addSubplot()
    ax2 = subp.addSubplot()

    ### set subplot properties

    nslices = sim.ncells
    #    nslices = 100                          # Number of slices to take in the y dir
    norm_ax0 = mpl.colors.Normalize(vmin=0, vmax=nslices)
    #    vertical_pos_colors_per_bead = cell2bead_vertical_pos(beads, cells, sim, nslices, ti)
    #    cmap_ax1 = sns.dark_palette((260, 75, 60), n_colors=nslices, input="husl", as_cmap=True)
    #    cmap_ax1 = sns.diverging_palette(255, 133, l=60, n=nslices, center="dark", as_cmap=True)
    cmap_ax0 = plt.cm.get_cmap('jet', quant_steps)

    ### plot the frames

    comx = deque()
    comy = deque()
    ntrace = 6
    delta = 20

    if tf + delta > sim.nsteps:
        tf -= delta

    for step in range(ti, tf):

        time = step * sim.dt
        print 'Step / Total : ', step, tf

        ### normalize variables for plotting purposes

        beads.xi[step, 0, :] /= sim.r_avg
        beads.xi[step, 1, :] /= sim.r_avg
        cells.xi[step, 0, :] /= sim.r_avg
        cells.xi[step, 1, :] /= sim.r_avg

        ### calculate the displacement magnitudes

        dr = calc_displacement_magnitudes(cells, step, delta, sim)
        norm_ax1 = mpl.colors.Normalize(vmin=min(dr), vmax=max(dr))

        ### keep the center of mass trajectory

        comx.append(cells.xi[step, 0, :])
        comy.append(cells.xi[step, 1, :])

        if step > ti + ntrace:
            comx.popleft()
            comy.popleft()

        ### plot

        subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b,
                                   total_subplots_in_x)

        ax0 = subp.addSubplot()
        ax1 = subp.addSubplot()
        ax2 = subp.addSubplot()

        text = r"$t/\tau_{D}$ = " + "{0:.2f}".format( time/sim.tau_D) + \
            r", $t/\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A)

        ### AX0

        line0 = ax0.scatter(beads.xi[step, 0, :], beads.xi[step, 1, :], s=4.0, \
                            c=beads.cid, \
                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=1.0, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        ax0.axis('scaled')

        ### labels

        ax0.set_xlabel(r"$x/R$", fontsize=40)
        ax0.set_ylabel(r"$y/R$", fontsize=40)

        ### limits

        ax0.set_xlim((full_box_downlim, full_box_uplim))
        ax0.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax0.xaxis.set_ticks(full_box_ticks)
        ax0.yaxis.set_ticks(full_box_ticks)
        ax0.tick_params(axis='both', which='major', labelsize=40)

        ### AX1

        line1 = ax1.scatter(cells.xi[step, 0, :], cells.xi[step, 1, :], s=6.0, \
                            c=np.arange(nslices), \
                            #c=dr,

                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=1.0, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        line2 = ax1.scatter(list(comx), list(comy), s=5.0, \
                            c=np.ones(np.shape(list(comx)))*np.arange(nslices), \
                            #c=np.ones(np.shape(list(comx)))*dr,

                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=0.5, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        ax1.axis('scaled')

        ### labels

        ax1.set_xlabel(r"$x/R$", fontsize=40)

        ### limits

        ax1.set_xlim((full_box_downlim, full_box_uplim))
        ax1.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax1.xaxis.set_ticks(full_box_ticks)
        plt.setp(ax1.get_yticklabels(), visible=False)
        ax1.tick_params(axis='both', which='major', labelsize=40)

        ### AX2

        line3 = ax2.scatter(cells.xi[step, 0, :], cells.xi[step, 1, :], s=5.0, \
                            c=dr,
                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=0.8, vmin=min(dr), vmax=max(dr), \
                            norm=norm_ax1, rasterized=True)

        line4 = ax2.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   np.cos(cells.pol[step]), np.sin(cells.pol[step]), \
                   dr, cmap=cmap_ax0, norm=norm_ax1, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=1.0)

        ax2.axis('scaled')

        ### labels

        ax2.set_xlabel(r"$x/R$", fontsize=40)

        ### limits

        ax2.set_xlim((full_box_downlim, full_box_uplim))
        ax2.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax2.xaxis.set_ticks(full_box_ticks)
        plt.setp(ax2.get_yticklabels(), visible=False)
        ax2.tick_params(axis='both', which='major', labelsize=40)

        plt.figtext(subp.beg + ax_len - 0.4 * ax_sep,
                    subp.ybeg + ax_len - 0.2 * ax_sep,
                    text,
                    fontsize=40)

        ### save

        savepath1 = savebase + "frame-" + "{0:05d}".format(int(step)) + ".png"
        if save_eps:
            savepath2 = savebase + "frame-" + "{0:05d}".format(
                int(step)) + ".eps"

        plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
        if save_eps:
            plt.savefig(savepath2,
                        dpi=300,
                        bbox_inches='tight',
                        pad_inches=0.08)
        fig.clf()

    return
Exemplo n.º 12
0
def plot_frames(beads, sim, ti, tf, savebase, save_eps):
    """ plot frames within the specified time window"""

    ### normalize variables for plotting purposes

    lx = sim.lx / sim.bl
    ly = sim.ly / sim.bl

    ### set general plot properties

    savebase += 'eps_' + str(sim.eps) + '_fp_' + str(sim.fp) + '_areak_' + str(
        sim.areak) + '/'
    os.system("mkdir -p " + savebase)
    quant_steps = 2056
    norm = mpl.colors.Normalize(vmin=0, vmax=sim.ncells)
    downlim = -2
    uplim = lx + 2
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot the frames

    for step in range(ti, tf):

        ### normalize variables for plotting purposes

        beads.xi[step, 0, :] /= sim.bl
        beads.xi[step, 1, :] /= sim.bl

        time = step * sim.dt
        print 'Step / Total : ', step, tf

        ### plot

        subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b,
                                   total_subplots_in_x)
        ax0 = subp.addSubplot()

        line0 = ax0.scatter(beads.xi[step, 0, :], beads.xi[step, 1, :], s=1, c=beads.cid, \
                            cmap=plt.cm.get_cmap('jet',quant_steps), \
                            edgecolors='None', alpha=0.7, vmin=0, vmax=sim.ncells, \
                            norm=norm, rasterized=True)

        ax0.axis('scaled')

        ### title

        ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
            ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

        ### labels

        ax0.set_xlabel("$x/r_{0}$", fontsize=40)
        ax0.set_ylabel("$y/r_{0}$", fontsize=40)

        ### limits

        ax0.set_xlim((downlim, uplim))
        ax0.set_ylim((downlim, uplim))

        ### ticks

        ax0.xaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
        ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
        ax0.tick_params(axis='both', which='major', labelsize=30)

        ### save

        savepath1 = savebase + "frame-" + "{0:05d}".format(int(step)) + ".png"
        if save_eps:
            savepath2 = savebase + "frame-" + "{0:05d}".format(
                int(step)) + ".eps"

        plt.savefig(savepath1, dpi=200, bbox_inches='tight', pad_inches=0.08)
        if save_eps:
            plt.savefig(savepath2,
                        dpi=200,
                        bbox_inches='tight',
                        pad_inches=0.08)
        fig.clf()

    return
Exemplo n.º 13
0
def plot_frames(data, beads, cells, sim, ti, tf, savebase, save_eps):
    """ plot frames within the specified time window"""

    ### normalize variables for plotting purposes

    lx = sim.lx / sim.r_avg
    ly = sim.ly / sim.r_avg

    ### vorticity information

    steps, xbins, ybins, w, vx, vy, v = data
    nwbins = int(max(xbins) + 1)
    xlin = np.linspace(0., lx, nwbins)
    ylin = np.linspace(0., ly, nwbins)
    xgrid, ygrid = np.meshgrid(xlin, ylin)

    ### set general plot properties

    savebase += 'eps_' + str(sim.eps) + '_fp_' + str(sim.fp) + \
        '_areak_' + str(sim.areak) + '/'
    os.system("mkdir -p " + savebase)
    quant_steps = 2056

    # limits
    full_box_downlim = -2
    full_box_uplim = lx + 2
    full_box_ticks = [0, 35, 70, 105, 135]

    half_box_downlim = 43
    half_box_uplim = 92
    half_box_ticks = [45, 90]

    num_ticks = 5

    ax_len = 2.2  # Length of one subplot square box
    ax_b = 0.01  # Beginning/offset of the subplot in the box
    ax_sep = 0.15  # Separation length between two subplots
    total_subplots_in_x = 2  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    multi = True
    ax1 = subp.addSubplot(multi)
    ax3 = subp.addSubplot(multi)
    ax0 = subp.addSubplot(multi)
    ax2 = subp.addSubplot(multi)

    ### set subplot properties

    nslices = sim.ncells
    norm_ax0 = mpl.colors.Normalize(vmin=0, vmax=nslices)
    cmap_ax0 = plt.cm.get_cmap('jet', quant_steps)

    ### plot the frames

    comx = deque()
    comy = deque()
    ntrace = 6
    delta = 4

    ### normalize central box positions for plotting purposes

    beads.xi /= sim.r_avg
    cells.xi /= sim.r_avg

    if tf + delta > sim.nsteps:
        tf -= delta

    for step in range(ti, tf):

        time = step * sim.dt
        print 'Step / Total : ', step, tf

        ### calculate the displacement magnitudes

        dx, dy, dr = calc_displacement_magnitudes(cells, step, delta, sim)
        dx /= sim.r_avg
        dy /= sim.r_avg
        dr /= sim.r_avg
        #norm_ax1 = mpl.colors.Normalize(vmin=min(dr), vmax=max(dr))

        ### keep the center of mass trajectory

        comx.append(cells.xi[step, 0, :])
        comy.append(cells.xi[step, 1, :])

        if step > ti + ntrace:
            comx.popleft()
            comy.popleft()

        ### get the vorticity and velocity information

        vs = v[steps == step]
        vmean = np.mean(vs)
        vn = np.zeros((nwbins, nwbins), dtype=np.float32)

        ws = w[steps == step]
        wmean = np.mean(np.abs(ws))
        wn = np.zeros((nwbins, nwbins), dtype=np.float32)

        for xi, yi in zip(xbins, ybins):
            xi = int(xi)
            yi = int(yi)
            wn[xi, yi] = ws[xi * nwbins + yi]
            vn[xi, yi] = vs[xi * nwbins + yi]

        vn /= vmean
        vmin = np.min(vn)
        vmax = np.max(vn)
        norm_ax2 = mpl.colors.Normalize(vmin=vmin, vmax=vmax)

        wn /= wmean
        wmin = np.min(wn)
        wmax = np.max(wn)
        norm_ax3 = mpl.colors.Normalize(vmin=wmin, vmax=wmax)

        ### plot

        subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b,
                                   total_subplots_in_x)
        ax1 = subp.addSubplot(multi)
        ax3 = subp.addSubplot(multi)
        ax0 = subp.addSubplot(multi)
        ax2 = subp.addSubplot(multi)

        text = r"$t/\tau_{D}$ = " + "{0:.2f}".format( time/sim.tau_D) + \
            r", $t/\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A)

        ### AX0

        line0 = ax0.scatter(beads.xi[step, 0, :], beads.xi[step, 1, :], s=4.0, \
                            c=beads.cid, \
                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=1.0, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        ax0.axis('scaled')

        ### labels

        ax0.set_ylabel(r"$y/R$", fontsize=40)

        ### limits

        ax0.set_xlim((full_box_downlim, full_box_uplim))
        ax0.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax0.xaxis.set_ticks(full_box_ticks)
        ax0.yaxis.set_ticks(full_box_ticks)
        plt.setp(ax0.get_xticklabels(), visible=False)
        ax0.tick_params(axis='both', which='major', labelsize=40)

        ### AX1

        line1 = ax1.scatter(cells.xi[step, 0, :], cells.xi[step, 1, :], s=6.0, \
                            c=np.arange(nslices), \
                            #c=dr,

                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=1.0, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        line2 = ax1.scatter(list(comx), list(comy), s=5.0, \
                            c=np.ones(np.shape(list(comx)))*np.arange(nslices), \
                            #c=np.ones(np.shape(list(comx)))*dr,

                            cmap=cmap_ax0, \
                            edgecolors='None', alpha=0.5, vmin=0, vmax=nslices, \
                            norm=norm_ax0, rasterized=True)

        ax1.axis('scaled')

        ### labels

        ax1.set_xlabel(r"$x/R$", fontsize=40)
        ax1.set_ylabel(r"$y/R$", fontsize=40)

        ### limits

        ax1.set_xlim((full_box_downlim, full_box_uplim))
        ax1.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax1.xaxis.set_ticks(full_box_ticks)
        ax1.yaxis.set_ticks(full_box_ticks)
        #plt.setp(ax1.get_yticklabels(),visible=False)
        ax1.tick_params(axis='both', which='major', labelsize=40)

        ### AX2

        line3 = ax2.contourf(
            xgrid,
            ygrid,
            vn.transpose(),
            cmap=cmap_ax0,
            #norm=norm_ax2, vmin=vmin, vmax=vmax)
        )

        line4 = ax2.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   dx, dy, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=0.7)

        ax2.axis('scaled')

        cax2 = plt.colorbar(line3, ax=ax2)
        #plt.colorbar(line5, cax=cax3, ticks=[])
        #cax2.ax.set_yticks([0.0, 0.3, 0.6, 0.9, 1.2 ,1.5])
        #cax3.set_yticklabels(['0', '0.7'])
        cax2.ax.tick_params(labelsize=40)
        cax2.ax.set_title(r"$|v|/<|v|>$", fontsize=40)

        ### labels

        #ax2.set_xlabel(r"$x/R$", fontsize=40)

        ### limits

        ax2.set_xlim((full_box_downlim, full_box_uplim))
        ax2.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        #ax2.xaxis.set_ticks(full_box_ticks)
        ax2.xaxis.set_ticks(full_box_ticks)
        ax2.yaxis.set_ticks(full_box_ticks)
        plt.setp(ax2.get_xticklabels(), visible=False)
        plt.setp(ax2.get_yticklabels(), visible=False)
        ax2.tick_params(axis='both', which='major', labelsize=40)

        ### AX3

        line6 = ax3.contourf(
            xgrid,
            ygrid,
            wn.transpose(),
            cmap=cmap_ax0,
            #norm=norm_ax3, vmin=wmin, vmax=wmax)
        )

        line7 = ax3.quiver(cells.xi[step, 0, :], cells.xi[step, 1, :], \
                   dx, dy, \
                   headwidth=5, headlength=6, headaxislength=3.5, alpha=1.0)

        ax3.axis('scaled')

        cax3 = plt.colorbar(line6, ax=ax3)
        #plt.colorbar(line5, cax=cax3, ticks=[])
        #cax3.ax.set_yticks([-6.0, -3.0, 0.0 , 3.0, 6.0])
        #cax3.set_yticklabels(['0', '0.7'])
        cax3.ax.tick_params(labelsize=40)
        cax3.ax.set_title(r"$\omega/<|\omega|>$", fontsize=40)

        ### labels

        ax3.set_xlabel(r"$x/R$", fontsize=40)

        ### limits

        ax3.set_xlim((full_box_downlim, full_box_uplim))
        ax3.set_ylim((full_box_downlim, full_box_uplim))

        ### ticks

        ax3.xaxis.set_ticks(full_box_ticks)
        ax3.yaxis.set_ticks(full_box_ticks)
        plt.setp(ax3.get_yticklabels(), visible=False)
        ax3.tick_params(axis='both', which='major', labelsize=40)

        ### text

        plt.figtext(subp.xbeg - 1.1 * ax_sep,
                    subp.ybeg + ax_len + 0.1 * ax_sep,
                    text,
                    fontsize=40)

        ### save

        savepath1 = savebase + "frame-" + "{0:05d}".format(int(step)) + ".png"
        if save_eps:
            savepath2 = savebase + "frame-" + "{0:05d}".format(
                int(step)) + ".eps"

        plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
        if save_eps:
            plt.savefig(savepath2,
                        dpi=300,
                        bbox_inches='tight',
                        pad_inches=0.08)
        fig.clf()

    return
Exemplo n.º 14
0
def plot_data(x, y, sim, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    label = '$\\phi=$' + str(sim.density) + '$,km=$' + str(sim.km)
    line0 = ax0.plot(x/sim.tau_D, y, \
                     linewidth=2.0, label=label)

    ### title

    #    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
    #        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

    ### labels

    ax0.set_xlabel("$\\Delta t/\\tau_{D}$", fontsize=40)
    ax0.set_ylabel("$Q(\\Delta t)$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))

    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    #    ax0.legend(bbox_to_anchor=(1.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
    #        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    savepath1 = base + savefolder + "_density_" + str(sim.density) + "_kappa_" + str(sim.kappa) + \
        "_km_" + str(sim.km) + '_panti_' + str(sim.pa) + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_density_" + str(sim.density) + "_kappa_" + str(sim.kappa) + \
        "_km_" + str(sim.km) + '_panti_' + str(sim.pa) + ".eps"
    plt.savefig(savepath1, dpi=200, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=200, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
def plot_data(x, data, param_choice, sims, savebase, savefolder):
    """ plot the data as a function of the chosen parameter"""

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    cnt = 0
    for p in data.keys():

        sim = sims[p]  # simulation information
        y = data[p]  # analysis data
        yth = th_msd(x, sim)  # theoretical result for MSD

        label = r'$\epsilon=$' + str(sim.eps) + '$,f_{m}=$' + str(sim.fp) + \
            '$,\kappa_{A}=$' + str(sim.areak) + '$,\kappa_{B}=$' + str(sim.kappa)
        color = list_from_cycle(ax0._get_lines.prop_cycler)[cnt]['color']
        line0 = ax0.loglog(x/sim.tau_D, y/sim.r_avg**2, \
                         linewidth=2.0, label=label, color=color)
        #        line1 = ax0.loglog(x/sim.tau_D, yth/sim.r_avg**2, '--', \
        #                         linewidth=1.0, label='_nolegend_', color=color)
        cnt += 1

    ax0.loglog(x / sim.tau_D, x / sim.tau_D, '--', linewidth=1.0, color='grey')
    ax0.loglog(x / sim.tau_D, (x / sim.tau_D)**2,
               '--',
               linewidth=1.0,
               color='grey')

    #    ax0.axvline(1./sim.Dr/sim.tau_D, color='black', alpha=0.5)
    #    ax0.axhline(1.0, color='black', alpha=0.5)

    ### title

    #    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
    #        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)

    ### labels

    ax0.set_xlabel(r"$t/\tau_{D}$", fontsize=30)
    ax0.set_ylabel(r"$\Delta r^{2}/R^{2}$", fontsize=30)

    ### limits

    #    ax0.set_xlim((1e-1, 5e2))
    ax0.set_ylim((1e-1, 1e6))
    ax0.set_ylim((1e-1, 1e10))

    ### ticks

    #    ax0.xaxis.set_ticks([1e-1, 1e0, 1e1, 1e2, 5e2])
    ax0.yaxis.set_ticks([1e-2, 1e0, 1e2, 1e4, 1e6])
    ax0.yaxis.set_ticks([1e-2, 1e0, 1e2, 1e4, 1e6, 1e8, 1e10])
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    ax0.legend(bbox_to_anchor=(0.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)

    savepath1 = base + savefolder + "_transition_per_" + param_choice + ".png"
    savepath2 = base + savefolder + "_transition_per_" + param_choice + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
def plot_data(data, a, savebase, savefolder, save_eps):
    """ plot the data as a function of the chosen parameter
    z encapsulates the data and sim info as a function of two parameters"""

    ### set general plot properties

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)
    #downlim = -1
    #uplim = sim.lx/4.   
    num_ticks = 5
    ax_len = 1.0                          # Length of one subplot square box
    ax_b = 0.0                            # Beginning/offset of the subplot in the box
    ax_sep = 0.0                          # Separation length between two subplots
    total_subplots_in_x = 1               # Total number of subplots    
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x) 
    ax0 = subp.addSubplot()
                          
    ### plot 

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x) 
    ax0 = subp.addSubplot()
    
    ### collect the values to be plotted in a numpy array
    
    x = np.zeros((len(data)), dtype=np.float32)
    y = np.zeros((len(data)), dtype=np.float32)
    z = np.zeros((len(data)), dtype=np.float32)
    
    for j, key in enumerate(data.keys()):
            
        #e, f = key                    # parameters
        #sim = data[key].sim           # simulation info for this parameter set
        z[j] = data[key].data          # analysis data
        x[j] = data[key].p1            # x value in the plot
        y[j] = data[key].p2            # y value in the plot 
        

    ### get the size and color code
    
    print z
    size = 1e+8 * np.pi * z**2
    quant_steps = 2056
    norm = mpl.colors.Normalize(vmin=0.0, vmax=max(z))       
    line0 = ax0.scatter(x, y, c=z, \
                        cmap=plt.cm.get_cmap('jet',quant_steps), \
                        edgecolors='None', alpha=1.0, vmin=0.0, vmax=max(z), \
                        norm=norm, rasterized=True) 
    fig.colorbar(line0, ax=ax0)
    

    ### title
    
#    ax0.set_title("$t/\\tau_{D}$ = " + "{0:.2f}".format(time/sim.tau_D) + \
#        ", $t/\\tau_{A}$ = " + "{0:.2f}".format(time/sim.tau_A), fontsize=30)
    
    ### labels
        
    ax0.set_xlabel("$\\epsilon$", fontsize=40)
    ax0.set_ylabel("$f_{m}$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    #ax0.set_ylim((downlim, uplim))
    
    ### ticks
    
    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    ax0.tick_params(axis='both', which='major', labelsize=30)
    
    ### legend

    ax0.legend(bbox_to_anchor=(1.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)
    
    ### save

    savepath1 = base + savefolder + "_per_AREAK_" + str(a) + ".png"
    if save_eps:
        savepath2 = base + savefolder + "_per_AREAK_" + str(a) + ".eps"            
    plt.savefig(savepath1, dpi=200, bbox_inches='tight', pad_inches=0.08)
    if save_eps:
        plt.savefig(savepath2, dpi=200, bbox_inches='tight', pad_inches=0.08)        
    fig.clf()                

        
    return
Exemplo n.º 17
0
def plot_data(x, data, param_choice, sims, savebase, savefolder):
    """ plot the data as a function of the chosen parameter"""

    ### set normalization parameter

    #knorm = np.pi/sims[data.keys()[0]].r_avg

    ### set general plot properties

    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    for p in data.keys():

        sim = sims[p]  # simulation information
        y = data[p]  # analysis data

        ### normalisation and appropriate data range selection

        print y
        histy, edges = np.histogram(y,
                                    bins=np.logspace(np.log10(min(y)),
                                                     np.log10(max(y))))
        print edges, histy

        ### curve fitting

        #        popt, pcov = curve_fit(power_law, xn, yn)
        #        yfit = power_law(xn, popt[0], popt[1])
        #        print "key = ", p,", fit param = ", popt[1]

        label = r'$\epsilon=$' + str(sim.eps) + '$,f_{m}=$' + str(sim.fp) + \
            '$,\kappa_{A}=$' + str(sim.areak)

        line0 = ax0.plot(edges[:-1], histy, \
                         linewidth=2.0, label=label)

        #ax0.set_xscale('log')

    ### labels

    ax0.set_xlabel(r"$q$", fontsize=30)
    ax0.set_ylabel(r"$D(q)$", fontsize=30)

    ### limits

    #    ax0.set_xlim((0, 22))
    #    ax0.set_ylim((0.0, 1.9))

    ### ticks

    #    ax0.xaxis.set_ticks([0, 10, 20])
    #    ax0.yaxis.set_ticks([0, 0.5, 1.0, 1.5])
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    ax0.legend(bbox_to_anchor=(0.35, 0.,0.65, 1.), loc=2, borderaxespad=0., \
        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    base = savebase + savefolder + '/'
    os.system("mkdir -p " + base)

    savepath1 = base + savefolder + "_transition_per_" + param_choice + ".png"
    savepath2 = base + savefolder + "_transition_per_" + param_choice + ".eps"
    plt.savefig(savepath1, dpi=300, bbox_inches='tight', pad_inches=0.08)
    plt.savefig(savepath2, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return
def plot_slices(phases, slicer):
    """ plot phase diagram by slices in 2D"""

    npoints = len(phases)  # total number of data points

    ### load the data

    idx = []
    x = []
    y = []
    z = []
    markers = []
    colors = []
    for j in xrange(npoints):
        idx.append(j)
        x.append(phases[j].eps)
        y.append(phases[j].fm)
        z.append(phases[j].data)
        markers.append(phases[j].marker)
        colors.append(phases[j].color)

    ### convert the lists into numpy arrays

    x = np.array(x, dtype=np.float32)
    y = np.array(y, dtype=np.float32)
    z = np.array(z, dtype=np.float32)
    idx = np.array(idx, dtype=np.int32)

    ### set plot properties

    savefolder = "/usr/users/iff_th2/duman/Cells_in_LAMMPS/PLOTS/PHASE_DIAGRAM/"
    os.system("mkdir -p " + savefolder)
    sfile = savefolder + "phase_diagram_from_corr_len_per_AREAK_" + \
        str(slicer)
    fig = plt.figure()
    ax_len = 0.9  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots in the x direction
    tick_num = 5  # Number of ticks
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    downlim_x = 0.03
    uplim_x = 35.0
    downlim_y = 0.3
    uplim_y = 15.0
    quant_steps = 2056
    norm = mpl.colors.Normalize(vmin=0, vmax=30)

    ### make these smaller to increase the resolution

    ax = subp.addSubplot()

    for xi, yi, zi, mi, ci in zip(x, y, z, markers, colors):
        line0 = ax.scatter(xi,
                           yi,
                           marker=mi,
                           c=zi,
                           s=30,
                           cmap=plt.cm.get_cmap('jet', quant_steps),
                           edgecolors='None',
                           alpha=1.0,
                           norm=norm,
                           vmin=0,
                           vmax=30)
    #ax.grid("on")

    cax = plt.colorbar(line0, ax=ax)
    cax.ax.set_title(r'$\xi_{r}$', fontsize=30)

    ax.set_title(r'$\kappa_{A} = $' + str(slicer), fontsize=30)

    ax.set_xscale('log')
    ax.set_yscale('log')

    ax.set_xlabel(r'$\epsilon$', fontsize=30)
    ax.set_ylabel(r'$f_{m}$', fontsize=30)
    ax.set_xlim((downlim_x, uplim_x))
    ax.set_ylim((downlim_y, uplim_y))
    #ax.xaxis.set_ticks( np.linspace(downlim, uplim, num=tick_num, endpoint=True) )
    #ax.yaxis.set_ticks( np.linspace(downlim, uplim, num=tick_num, endpoint=True) )
    ax.tick_params(axis='both', which='major', labelsize=30)

    ### save the figure

    plt.savefig(sfile + '.eps', dpi=300, bbox_inches='tight', pad_inches=0.08)
    plt.savefig(sfile + '.png', dpi=300, bbox_inches='tight', pad_inches=0.08)
    plt.clf()

    return
Exemplo n.º 19
0
def plot_data(data, param_choice, args):
    """ plot the frames per parameter"""

    ### set general plot properties

    savebase = '/usr/users/iff_th2/duman/Cells_in_LAMMPS/POVRAY/'
    #downlim = -1
    #uplim = sim.lx/4.
    num_ticks = 5
    ax_len = 1.0  # Length of one subplot square box
    ax_b = 0.0  # Beginning/offset of the subplot in the box
    ax_sep = 0.0  # Separation length between two subplots
    total_subplots_in_x = 1  # Total number of subplots
    fig = plt.figure()
    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    name = ''
    pname = ''
    if param_choice == 'areak':
        name = 'AREAK'
        pname = name + '_eps_' + str(args.eps) + '_fp_' + str(args.fp) + \
            '_kappa_' + str(args.kappa)
        xlab = '$\kappa_A$'
        tit = '$\epsilon=$' + str(args.eps) + ',$f_m=$' + str(args.fp) + \
            ',$\kappa=$' + str(args.kappa)
    elif param_choice == 'eps':
        name = 'EPS'
        pname = name + '_fp_' + str(args.fp) + '_areak_' + str(args.areak) + \
            '_kappa_' + str(args.kappa)
        xlab = '$\epsilon$'
        tit = '$f_m=$' + str(args.fp) + ',$\kappa_A=$' + str(args.areak) + \
            ',$\kappa=$' + str(args.kappa)
    elif param_choice == 'fp':
        name = 'FP'
        pname = name + '_eps_' + str(args.eps) + '_areak_' + str(args.areak) + \
            '_kappa_' + str(args.kappa)
        xlab = '$f_{m}$'
        tit = '$\epsilon=$' + str(args.eps) + ',$\kappa_A=$' + str(args.areak) + \
            ',$\kappa=$' + str(args.kappa)
    elif param_choice == 'kappa':
        name = 'KAPPA'
        pname = name + '_eps_' + str(args.eps) + '_fp_' + str(args.fp) + \
            '_areak_' + str(args.areak)
        xlab = '$\kappa$'
        tit = '$\epsilon=$' + str(args.eps) + ',$f_m=$' + str(args.fp) + \
            ',$\kappa_A=$' + str(args.areak)
    base = savebase + name + '/'
    os.system("mkdir -p " + base)

    ### plot

    subp = misc_tools.Subplots(fig, ax_len, ax_sep, ax_b, total_subplots_in_x)
    ax0 = subp.addSubplot()

    x = data.keys()
    y = [1 for j in range(len(data.keys()))]
    print x
    ax0.scatter(x, y)
    ax0.set_xscale('log')
    ax0.set_yscale('log')

    for j, p in enumerate(data.keys()):

        fname = data[p]

        if os.path.exists(fname):
            arr_hand = read_png(fname)

            zoom = 0.099
            imagebox = OffsetImage(arr_hand, zoom=zoom)

            xy = [x[j], y[j]]  # coordinates to position this image

            ab = AnnotationBbox(imagebox,
                                xy,
                                xybox=(0., -0.),
                                xycoords='data',
                                boxcoords="offset points",
                                frameon=1,
                                pad=.1)

            ax0.add_artist(ab)

    ### title

    ax0.set_title(tit, fontsize=30)

    ### labels

    ax0.set_xlabel(xlab, fontsize=30)
    #ax0.set_ylabel("$F_{s}(q,\\Delta t)$", fontsize=40)

    ### limits

    #ax0.set_xlim((-1, 15))
    ax0.set_ylim((0.9999, 1.0001))

    ax0.grid(1, color='#cccccc', linestyle='--')
    ax0.set_frame_on(False)
    ax0.get_xaxis().tick_bottom()
    ax0.axes.get_yaxis().set_visible(False)
    xmin, xmax = ax0.get_xaxis().get_view_interval()
    ymin, ymax = ax0.get_yaxis().get_view_interval()
    ax0.add_artist(
        Line2D((xmin, xmax), (ymin, ymin), color='black', linewidth=2))
    ### ticks

    #ax0.xaxis.set_ticks(np.linspace(0, 15, num_ticks, endpoint=True))
    #ax0.yaxis.set_ticks(np.linspace(0, uplim, num_ticks, endpoint=True))
    plt.setp(ax0.get_yticklabels(), visible=False)
    ax0.tick_params(axis='both', which='major', labelsize=30)

    ### legend

    #    ax0.legend(bbox_to_anchor=(1.005, 0.,0.65, 1.), loc=2, borderaxespad=0., \
    #        prop={'size': 20}, mode="expand", frameon=False)

    ### save

    savepath = base + "images_per_" + pname + ".pdf"
    print savepath
    plt.savefig(savepath, dpi=300, bbox_inches='tight', pad_inches=0.08)
    fig.clf()

    return