Esempio n. 1
0
    def plot(self, nbin_sin2psi=2, iopt=0, ylim=None, mxnphi=None, hkl='211'):
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        if hasattr(self, 'vf'): nh = 2
        else: nh = 1

        if mxnphi == None: mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi, nh=nh, w0=0, w1=0, left=0.2, right=0.15)

        # mx = max(self.flow.epsilon_vm)
        # mn = min(self.flow.epsilon_vm)
        mx = 1.
        mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)
        colors = []
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i == 0: colors.append(cl)

                y = self.ig[j, i, :]
                figs.axes[i].plot(np.sign(self.psi) *
                                  sin(self.psi * np.pi / 180.)**2,
                                  y,
                                  '-x',
                                  color=cl)

                if j == 0:
                    figs.axes[i].set_title(r'$\phi: %3.1f^\circ{}$' %
                                           self.phi[i])

        deco = axes_label.__deco__
        rm_inner = mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u

        deco(figs.axes[0], iopt=2, ipsi_opt=1)
        for i in xrange(len(figs.axes)):
            figs.axes[i].set_xlim(-0.5, 0.5)
        mpl_lib.tune_xy_lim(figs.axes)
        rm_inner(figs.axes)
        ticks_bin_u(figs.axes, n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])
        mpl_lib.add_cb(ax=axcb,
                       filled=False,
                       norm=norm,
                       levels=self.flow.epsilon_vm,
                       colors=colors,
                       ylab='Equivalent strain')
Esempio n. 2
0
    def plot(self, nbin_sin2psi=2, iopt=0,ylim=None,
             mxnphi=None,hkl='211'):
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        if hasattr(self,'vf'): nh = 2
        else: nh = 1

        if mxnphi==None: mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi,nh=nh,w0=0,w1=0,
                        left=0.2,right=0.15)

        # mx = max(self.flow.epsilon_vm)
        # mn = min(self.flow.epsilon_vm)
        mx = 1.
        mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx,mn=mn)
        colors=[]
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i==0: colors.append(cl)

                y = self.ig[j,i,:]
                figs.axes[i].plot(
                    np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                    y,'-x',color=cl)

                if j==0:
                    figs.axes[i].set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[i])

        deco = axes_label.__deco__
        rm_inner =mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u

        deco(figs.axes[0],iopt=2,ipsi_opt=1)
        for i in xrange(len(figs.axes)):
            figs.axes[i].set_xlim(-0.5,0.5)
        mpl_lib.tune_xy_lim(figs.axes)
        rm_inner(figs.axes)
        ticks_bin_u(figs.axes,n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88,b.y0,0.03,b.y1-b.y0])
        mpl_lib.add_cb(ax=axcb,filled=False,norm=norm,
                       levels=self.flow.epsilon_vm,
                       colors=colors,ylab='Equivalent strain')
Esempio n. 3
0
    def plot(self, istps=[-1]):
        ps = []
        nstps = len(istps)
        for istp in xrange(len(istps)):
            ps.append(self.P_scan[istp])

        import matplotlib.pyplot as plt
        import MP
        from MP.lib import mpl_lib
        wide_fig = mpl_lib.wide_fig
        rm_lab = mpl_lib.rm_lab
        rm_inner = mpl_lib.rm_inner
        ticks_bins_ax_u = mpl_lib.ticks_bins_ax_u
        ticks_bins_ax_u = mpl_lib.ticks_bins_ax_u
        tune_xy_lim = mpl_lib.tune_xy_lim

        figs = wide_fig(nw=self.nphis,
                        nh=len(istps),
                        w0=0,
                        w1=0,
                        left=0.15,
                        h0=0,
                        h1=0,
                        up=0.1,
                        down=0.1)
        # axest = []
        # for i in xrange(len(figs.axes)):
        #     tax = figs.axes[i].twinx()
        #     axest.append(tax)

        for istp in xrange(nstps):
            for iphi in xrange(self.nphis):
                iax = self.nphis * istp + iphi
                X = []
                Y = []
                Y0 = []
                for ipsi in xrange(ps[istp].protophi[iphi].npsi):
                    x = np.sin(
                        ps[istp].protophi[iphi].\
                        ppscans[ipsi].psi*np.pi/180.)**2
                    y = ps[istp].protophi[iphi].\
                        ppscans[ipsi].dspc
                    y0 = ps[istp].protophi[iphi].\
                         ppscans[ipsi].ints
                    X.append(x)
                    Y.append(y)
                    Y0.append(y0)

                figs.axes[iax].plot(X, Y, '-x')
                #axest[iax].plot(X,Y0,'-gx',alpha=0.5)

                if istp == nstps - 1:                    figs.axes[iax].set_title(
                    r'$\phi=%3.1f^\circ{}$'%(ps[istp].\
                           protophi[iphi].phi))

        ticks_bins_ax_u(figs.axes, n=5)
        tune_xy_lim = mpl_lib.tune_xy_lim(figs.axes)
        #tune_xy_lim = mpl_lib.tune_xy_lim(axest)
        rm_inner(figs.axes)
Esempio n. 4
0
    def plot(self,istps=[-1]):
        ps = []
        nstps = len(istps)
        for istp in range(len(istps)):
            ps.append(self.P_scan[istp])


        import matplotlib.pyplot as plt
        import MP
        from MP.lib import mpl_lib
        wide_fig = mpl_lib.wide_fig
        rm_lab   = mpl_lib.rm_lab
        rm_inner = mpl_lib.rm_inner
        ticks_bins_ax_u = mpl_lib.ticks_bins_ax_u
        ticks_bins_ax_u = mpl_lib.ticks_bins_ax_u
        tune_xy_lim  = mpl_lib.tune_xy_lim

        figs = wide_fig(nw=self.nphis,
                        nh=len(istps),
                        w0=0,w1=0,left=0.15,h0=0,h1=0,
                        up=0.1,down=0.1)
        # axest = []
        # for i in range(len(figs.axes)):
        #     tax = figs.axes[i].twinx()
        #     axest.append(tax)

        for istp in range(nstps):
            for iphi in range(self.nphis):
                iax = self.nphis * istp + iphi
                X = []
                Y = []; Y0 = []
                for ipsi in range(ps[istp].protophi[iphi].npsi):
                    x = np.sin(
                        ps[istp].protophi[iphi].\
                        ppscans[ipsi].psi*np.pi/180.)**2
                    y = ps[istp].protophi[iphi].\
                        ppscans[ipsi].dspc
                    y0 = ps[istp].protophi[iphi].\
                         ppscans[ipsi].ints
                    X.append(x); Y.append(y)
                    Y0.append(y0)


                figs.axes[iax].plot(X,Y,'-x')
                #axest[iax].plot(X,Y0,'-gx',alpha=0.5)

                if istp==nstps-1: figs.axes[iax].set_title(
                        r'$\phi=%3.1f^\circ{}$'%(ps[istp].\
                                         protophi[iphi].phi))

        ticks_bins_ax_u(figs.axes,n=5)
        tune_xy_lim = mpl_lib.tune_xy_lim(figs.axes)
        #tune_xy_lim = mpl_lib.tune_xy_lim(axest)
        rm_inner(figs.axes)
Esempio n. 5
0
def plot_xy_disc_e33dot(
        dat,
        istp=-1,
        ax=None,
        icol=11,
        fang=90,
        dist_bb=[5, 10],  ## backbone
        dist_rb=[1, 5]):
    """
    Extract DIC data from 'disc' area
    """
    from MP.lib.mpl_lib import wide_fig as wf
    from MP.lib.mpl_lib import rm_all_lab as ral
    import matplotlib as mpl
    from MP.lib import mpl_lib
    from MP import ssort

    sort = ssort.shellSort
    d = dat[istp, :, :]
    dz = np.log10(abs(d[:, icol]))
    for i in range(len(dz)):
        if dz[i] == np.inf or dz[i] == -np.inf:
            dz[i] = np.nan
    mn = min(dz)
    mx = max(dz)
    norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
    cmap, m = mpl_lib.norm_cmap(mn=mn, mx=mx, cm_name='brg')
    n = d.shape[0]

    ## find values in the back-bone branch shape
    ids = []
    xs = []
    ys = []
    zs = []
    for i in range(n):
        x, y, z = d[i, 0], d[i, 1], -d[i, icol]
        if np.isnan(z): pass
        else:
            zs.append(d[i, icol])
            ids.append(i)
            xs.append(d[i, 0])
            ys.append(d[i, 1])
        c = m.to_rgba(np.log10(z))
        ax.plot(x, y, 'o', ms=1.5, color=c, mfc=c, mec='None')

    val, ind = sort(zs)
    imn = ids[ind[0]]
    ax.plot(d[imn, 0], d[imn, 1], 'g.')  ## minimum

    ## draw a backbone grid
    x0, y0 = d[imn, 0], d[imn, 1]  # center of backbone

    db = np.array(dist_bb)
    dr = np.array(dist_rb)
    DB = []
    DR = []
    for i in range(len(db)):
        DB.append(-db[-i - 1])
    DB.append(0)
    for i in range(len(db)):
        DB.append(db[i])
    for i in range(len(dr)):
        DR.append(-dr[-i - 1])
    DR.append(0)
    for i in range(len(dr)):
        DR.append(dr[i])

    db = DB[::]
    dr = DR[::]
    xy_db_dr = np.zeros((len(db), len(dr), 2))
    for i in range(len(db)):
        for j in range(len(dr)):
            xy_db_dr[i, j, :] = db[i], dr[j]

    ## rotate xy by fang
    for i in range(len(db)):
        for j in range(len(dr)):
            y, x = xy_db_dr[i, j, :]
            xy_db_dr[i, j, :] = rot_xy([x, y], fang)

    ## translate
    xy_db_dr[:, :, 0] = xy_db_dr[:, :, 0] + x0
    xy_db_dr[:, :, 1] = xy_db_dr[:, :, 1] + y0

    ## print xy_db_dr.shape
    ## return xy_db_dr

    if len(db) > 3:
        nw = len(db) / 3
        nh = 4

    fig = wf(nw=nw,
             nh=nh,
             w0=0.0,
             ws=1.0,
             w1=0.0,
             h0=0.0,
             hs=1.0,
             h1=0.0,
             uw=2.3,
             uh=2.3,
             left=0.2,
             up=0.1,
             down=0.2,
             iarange=True)
    fig1 = wf(nw=2,
              nh=2,
              w0=0.1,
              ws=0.7,
              w1=0.2,
              h0=0.1,
              hs=0.7,
              h1=0.2,
              uw=2.3,
              uh=2.3,
              left=0.2,
              up=0.1,
              down=0.2,
              iarange=True)
    iax = 0
    sym = [
        'k^', 'k+', 'kd', 'kx', 'k<', 'k>', 'k*', 'k1', 'k2', 'k3', 'k4', 'k8',
        'ks', 'kp', 'kh', 'kH', 'kD'
    ]

    ## thickness strain rate
    epst_dot_av = []
    epst_dot_std = []
    ## epsxx
    exx_av = []
    exx_std = []
    ## epsyy
    eyy_av = []
    eyy_std = []
    for i in range(len(db)):
        indices_along_ribs = []
        for j in range(len(dr)):
            x, y = xy_db_dr[i, j, :]
            ind = find_nearest([x, y], xs, ys, err=2)
            if not (np.isnan(ind)):
                indices_along_ribs.append(ids[ind])

        epsx = []
        epsy = []
        epst_dot = []
        coord = []
        for k in range(len(indices_along_ribs)):
            indx = indices_along_ribs[k]
            x = d[indx, 0]
            y = d[indx, 1]
            coord.append([x, y])
            ## ax.plot(x,y,sym[i],ms=3)
            ex = dat[:, indx, 3]
            ey = dat[:, indx, 4]

            et = dat[:, indx, 12]

            ex_d = dat[:, indx, 9]
            ey_d = dat[:, indx, 10]
            ez_d = ex_d + ey_d  ## positive value
            epst_dot.append(ez_d)
            epsx.append(ex)
            epsy.append(ey)

            fig.axes[iax].plot(ez_d)

        iax = iax + 1
        x, y = np.array(coord).T[:]
        ax.plot(x, y, '-', color='k', alpha=0.5)

        epst_dot = np.array(epst_dot).T
        epsx = np.array(epsx).T
        epsy = np.array(epsy).T

        D = []
        D_e = []
        E_ex = []
        E_exe = []
        E_ey = []
        E_eye = []
        for j in range(len(epst_dot)):  ## number of ribs
            D.append(np.mean(epst_dot[j]))
            D_e.append(np.std(epst_dot[j]))
            E_ex.append(np.mean(epsx[j]))
            E_exe.append(np.std(epsx[j]))
            E_ey.append(np.mean(epsy[j]))
            E_eye.append(np.std(epsy[j]))

    ## fig1.axes[0].plot(D,label=db[i])
        epst_dot_av.append(D)
        epst_dot_std.append(D_e)
        exx_av.append(E_ex)
        exx_std.append(E_exe)
        eyy_av.append(E_ey)
        eyy_std.append(E_eye)

    ## find maximum D value's index to trim the data
    ndat = (len(epst_dot_av) - 1) / 2 + 1
    ref = epst_dot_av[ndat - 1]  ## data at necking center spot
    _ref_ = []
    _ind_ = []
    for i in range(len(ref)):
        if not (np.isnan(ref[i])):
            _ref_.append(ref[i])
            _ind_.append(i)
    _val_, _i_ = sort(_ref_)
    ix = _ind_[_i_[-1]]

    mdat = np.zeros((2, 2, ndat))
    c = []

    for i in range(ndat):
        i0 = i
        i1 = -i - 1
        ## thickness strain rate
        d1 = epst_dot_av[i0]
        d2 = epst_dot_av[i1]
        e1 = epst_dot_std[i0]
        e2 = epst_dot_std[i1]
        d = []
        e = []

        ## epsilon xx
        ex1 = exx_av[i0]
        ex2 = exx_av[i1]
        exe1 = exx_std[i0]
        exe2 = exx_std[i1]
        ex = []
        exe = []

        ## epsilon yy
        ey1 = eyy_av[i0]
        ey2 = eyy_av[i1]
        eye1 = eyy_std[i0]
        eye2 = eyy_std[i1]
        ey = []
        eye = []

        for j in range(len(d1)):  # along the time axis
            d.append((d1[j] + d2[j]) / 2.)
            e.append((e1[j] + e2[j]) / 2.)
            ex.append((ex1[j] + ex2[j]) / 2.)
            exe.append((exe1[j] + exe2[j]) / 2.)
            ey.append((ey1[j] + ey2[j]) / 2.)
            eye.append((eye1[j] + eye2[j]) / 2.)

        xind = np.arange(len(d)) + 1
        p = 0.7
        i0 = int(float(len(xind)) * p)
        ## find maximum value and index?
        l, = fig1.axes[0].plot(xind, d, '-', label=abs(db[-i - 1]))
        fig1.axes[1].plot(xind[i0:ix + 1], d[i0:ix + 1], '+')
        fig1.axes[2].errorbar(xind[i0:ix + 1],
                              d[i0:ix + 1],
                              yerr=e1[i0:ix + 1],
                              fmt='+')

        l, = fig1.axes[3].plot(ex[i0:ix + 1], ey[i0:ix + 1])
        fig1.axes[3].errorbar(ex[ix],
                              ey[ix],
                              color=l.get_color(),
                              xerr=exe[ix],
                              yerr=eye[ix])

        mdat[0, 0, i] = ex[ix]
        mdat[0, 1, i] = ey[ix]
        mdat[1, 0, i] = exe[ix]
        mdat[1, 1, i] = eye[ix]
        c.append(l.get_color())

    ## deco
    from MP.lib.mpl_lib import tune_xy_lim
    tune_xy_lim(fig.axes)
    fig1.axes[2].set_yscale('log')
    fig1.axes[2].set_ylim(1e-3)
    fig1.axes[0].legend(loc='best',ncol=2,fontsize=5).\
        get_frame().set_alpha(0.5)
    return fig, fig1, mdat, c
Esempio n. 6
0
def plot_xy_disc_e33dot(
        dat,istp=-1,ax=None,icol=11,fang=90,
        dist_bb=[5,10], ## backbone
        dist_rb=[1,5]):
    """
    Extract DIC data from 'disc' area
    """
    from MP.lib.mpl_lib import wide_fig as wf
    from MP.lib.mpl_lib import rm_all_lab as ral
    import matplotlib as mpl
    from MP.lib import mpl_lib
    from MP import ssort

    sort=ssort.shellSort
    d=dat[istp,:,:]
    dz = np.log10(abs(d[:,icol]))
    for i in range(len(dz)):
        if dz[i]==np.inf or dz[i]==-np.inf:
            dz[i] = np.nan
    mn=min(dz);mx=max(dz)
    norm=mpl.colors.Normalize(vmin=mn, vmax=mx)
    cmap, m = mpl_lib.norm_cmap(
        mn=mn,mx=mx,cm_name='brg')
    n=d.shape[0]

    ## find values in the back-bone branch shape
    ids = []; xs = []; ys = []; zs = []
    for i in range(n):
        x,y,z=d[i,0],d[i,1],-d[i,icol]
        if np.isnan(z): pass
        else:
            zs.append(d[i,icol])
            ids.append(i)
            xs.append(d[i,0])
            ys.append(d[i,1])
        c = m.to_rgba(np.log10(z))
        ax.plot(x,y,'o',ms=1.5,
                color=c,mfc=c,mec='None')

    val, ind = sort(zs)
    imn = ids[ind[0]]
    ax.plot(d[imn,0],d[imn,1],'g.') ## minimum

    ## draw a backbone grid
    x0,y0=d[imn,0],d[imn,1] # center of backbone

    db=np.array(dist_bb); dr=np.array(dist_rb)
    DB=[]; DR=[]
    for i in range(len(db)):
        DB.append(-db[-i-1])
    DB.append(0)
    for i in range(len(db)):
        DB.append(db[i])
    for i in range(len(dr)):
        DR.append(-dr[-i-1])
    DR.append(0)
    for i in range(len(dr)):
        DR.append(dr[i])

    db=DB[::];dr=DR[::]
    xy_db_dr = np.zeros((len(db),len(dr),2))
    for i in range(len(db)):
        for j in range(len(dr)):
            xy_db_dr[i,j,:] = db[i], dr[j]

    ## rotate xy by fang
    for i in range(len(db)):
        for j in range(len(dr)):
            y,x = xy_db_dr[i,j,:]
            xy_db_dr[i,j,:] = rot_xy([x,y],fang)

    ## translate
    xy_db_dr[:,:,0] =     xy_db_dr[:,:,0] + x0
    xy_db_dr[:,:,1] =     xy_db_dr[:,:,1] + y0

    ## print xy_db_dr.shape
    ## return xy_db_dr

    if len(db)>3:
        nw = len(db)/3
        nh = 4

    fig=wf(nw=nw,nh=nh,w0=0.0,ws=1.0,w1=0.0,
           h0=0.0,hs=1.0,h1=0.0,uw=2.3,uh=2.3,
           left=0.2,up=0.1,down=0.2,iarange=True)
    fig1=wf(nw=2,nh=2,w0=0.1,ws=0.7,w1=0.2,
            h0=0.1,hs=0.7,h1=0.2,uw=2.3,uh=2.3,
            left=0.2,up=0.1,down=0.2,iarange=True)
    iax=0
    sym=['k^','k+','kd','kx','k<','k>','k*',
         'k1','k2','k3','k4','k8','ks','kp',
         'kh','kH','kD']

    ## thickness strain rate
    epst_dot_av = []; epst_dot_std = []
    ## epsxx
    exx_av      = []; exx_std      = []
    ## epsyy
    eyy_av      = []; eyy_std      = []
    for i in range(len(db)):
        indices_along_ribs = []
        for j in range(len(dr)):
            x,y = xy_db_dr[i,j,:]
            ind = find_nearest([x,y],xs,ys,err=2)
            if not(np.isnan(ind)):
                indices_along_ribs.append(ids[ind])

        epsx = []; epsy = []; epst_dot = []
        coord = []
        for k in range(len(indices_along_ribs)):
            indx = indices_along_ribs[k]
            x = d[indx,0]; y = d[indx,1]
            coord.append([x,y])
            ## ax.plot(x,y,sym[i],ms=3)
            ex=dat[:,indx,3]
            ey=dat[:,indx,4]


            et=dat[:,indx,12]

            ex_d=dat[:,indx,9]
            ey_d=dat[:,indx,10]
            ez_d=ex_d+ey_d ## positive value
            epst_dot.append(ez_d)
            epsx.append(ex)
            epsy.append(ey)

            fig.axes[iax].plot(ez_d)

        iax = iax + 1
        x,y = np.array(coord).T[:]
        ax.plot(x,y,'-',color='k',alpha=0.5)

        epst_dot=np.array(epst_dot).T
        epsx    =np.array(epsx).T
        epsy    =np.array(epsy).T

        D    = []; D_e   = [];
        E_ex = []; E_exe = [];
        E_ey = []; E_eye = [];
        for j in range(len(epst_dot)): ## number of ribs
            D.append(np.mean(epst_dot[j]))
            D_e.append(np.std(epst_dot[j]))
            E_ex.append(np.mean(epsx[j]))
            E_exe.append(np.std(epsx[j]))
            E_ey.append(np.mean(epsy[j]))
            E_eye.append(np.std(epsy[j]))

    ## fig1.axes[0].plot(D,label=db[i])
        epst_dot_av.append(D)
        epst_dot_std.append(D_e)
        exx_av.append(E_ex)
        exx_std.append(E_exe)
        eyy_av.append(E_ey)
        eyy_std.append(E_eye)

    ## find maximum D value's index to trim the data
    ndat = (len(epst_dot_av)-1)/2+1
    ref=epst_dot_av[ndat-1] ## data at necking center spot
    _ref_=[]; _ind_ =[]
    for i in range(len(ref)):
        if not(np.isnan(ref[i])):
            _ref_.append(ref[i]); _ind_.append(i)
    _val_, _i_ = sort(_ref_)
    ix = _ind_[_i_[-1]]

    mdat = np.zeros((2,2,ndat))
    c    = []

    for i in range(ndat):
        i0 =  i
        i1 = -i -1
        ## thickness strain rate
        d1=epst_dot_av[i0];  d2=epst_dot_av[i1]
        e1=epst_dot_std[i0]; e2=epst_dot_std[i1]
        d =[]; e=[]

        ## epsilon xx
        ex1  = exx_av[i0];  ex2  = exx_av[i1]
        exe1 = exx_std[i0]; exe2 = exx_std[i1]
        ex=[]; exe=[]

        ## epsilon yy
        ey1  = eyy_av[i0];  ey2  = eyy_av[i1]
        eye1 = eyy_std[i0]; eye2 = eyy_std[i1]
        ey=[]; eye=[]

        for j in range(len(d1)):  # along the time axis
            d.append((d1[j]+d2[j])/2.)
            e.append((e1[j]+e2[j])/2.)
            ex.append((ex1[j]+ex2[j])/2.)
            exe.append((exe1[j]+exe2[j])/2.)
            ey.append((ey1[j]+ey2[j])/2.)
            eye.append((eye1[j]+eye2[j])/2.)

        xind=np.arange(len(d))+1
        p = 0.7
        i0 = int(float(len(xind))*p)
        ## find maximum value and index?
        l, =fig1.axes[0].plot(xind,d,'-',label=abs(db[-i-1]))
        fig1.axes[1].plot(xind[i0:ix+1],d[i0:ix+1],'+')
        fig1.axes[2].errorbar(xind[i0:ix+1],d[i0:ix+1],
                              yerr=e1[i0:ix+1],fmt='+')

        l, =fig1.axes[3].plot(ex[i0:ix+1],ey[i0:ix+1])
        fig1.axes[3].errorbar(
            ex[ix],ey[ix],color=l.get_color(),
            xerr=exe[ix],yerr=eye[ix])

        mdat[0,0,i] = ex[ix]
        mdat[0,1,i] = ey[ix]
        mdat[1,0,i] = exe[ix]
        mdat[1,1,i] = eye[ix]
        c.append(l.get_color())

    ## deco
    from MP.lib.mpl_lib import tune_xy_lim
    tune_xy_lim(fig.axes)
    fig1.axes[2].set_yscale('log')
    fig1.axes[2].set_ylim(1e-3)
    fig1.axes[0].legend(loc='best',ncol=2,fontsize=5).\
        get_frame().set_alpha(0.5)
    return fig,fig1,mdat,c
Esempio n. 7
0
    def plot(self,nbin_sin2psi=2,iopt=0,ylim=None,
             mxnphi=None,hkl='211'):
        """
        Arguments
        =========
        nbin_sin2psi = 2
        iopt         = iopt
        ylim         = None
        mxnphi       = None
        hkl          = '211'
        """
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        import matplotlib.pyplot as plt
        if hasattr(self, 'vf'):
            nh = 3
        else: nh = 2

        if type(mxnphi)==type(None): mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi,nh=nh,w0=0,w1=0,
                        left=0.2,right=0.15)
        mx = max(self.flow.epsilon_vm)
        mn = min(self.flow.epsilon_vm)
        #mx = 1.
        #mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx,mn=mn)
        colors=[]
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i==0: colors.append(cl)

                y = self.sf[j,i,:,0].copy() * 1e12
                l, = figs.axes[i].plot(
                    np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                    y,'-x',color=cl)
                y = self.sf[j,i,:,1].copy() * 1e12
                figs.axes[i+mxnphi].plot(
                    np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                    y,'-+',color=cl)

                if j==0:
                    figs.axes[i].set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[i])

        if nh==3:
            for i in xrange(mxnphi):
                for j in xrange(self.flow.nstp):
                    eps = self.flow.epsilon_vm[j]
                    cl = c.to_rgba(eps)
                    y = self.vf[j,i,:]
                    figs.axes[i+mxnphi*2].plot(
                        np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                        y,'-',color=cl)

        deco = axes_label.__deco__
        rm_inner =mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u
        rm_inner(figs.axes[:mxnphi*2])
        if nh==3: rm_inner(figs.axes[mxnphi*2:mxnphi*3])
        deco(figs.axes[0],iopt=1,ipsi_opt=1,hkl=hkl)
        if nh==3: deco(figs.axes[mxnphi*2],iopt=7,ipsi_opt=1,hkl=hkl)
        mpl_lib.tune_xy_lim(figs.axes[:mxnphi*2])
        if ylim!=None:
            for i in xrange(len(figs.axes[:mxnphi*2])):
                figs.axes[i].set_ylim(ylim)
        if nh==3: mpl_lib.tune_xy_lim(figs.axes[mxnphi*2:mxnphi*3])
        ticks_bin_u(figs.axes[:mxnphi*2],n=4)
        if nh==3: ticks_bin_u(figs.axes[mxnphi*2:mxnphi*3],n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88,b.y0,0.03,b.y1-b.y0])
        mpl_lib.add_cb(ax=axcb,filled=False,norm=norm,
                       levels=self.flow.epsilon_vm,
                       format='%5.3f',
                       colors=colors,ylab='Equivalent strain')

        if nh==1 or nh==2: return

        """   SF(phi,psi) vs plastic strain   """
        ## binning sin2psi
        nbin = nbin_sin2psi
        indx = self.__binning__(nbin=nbin,mx=0.5)

        for i in xrange(len(indx)):
            print '%i bin'%(i+1)
            for j in xrange(len(indx[i])):
                print '%4i'%indx[i][j],
                print '%4.2f'%(self.sin2psi[indx[i][j]]),
            print

        if mxnphi!=None: mxnphi=self.nphi
        figs_p = wide_fig(nw=mxnphi,nh=nbin,
                          w0=0,w1=0,left=0.2,right=0.15)

        eps = self.flow.epsilon_vm
        for i in xrange(mxnphi):
            for j in xrange(nbin):
                ax = figs_p.axes[i+mxnphi*j]
                if j==nbin-1: ax.set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[i])
                idx = indx[j]
                for k in xrange(len(idx)):
                    y = self.sf[:,i,[idx[k]],0][::]
                    ax.plot(eps,y,'x')

        for i in xrange(nbin):
            axes=[]
            for j in xrange(mxnphi*2):
                axes.append(figs_p.axes[j+mxnphi*i])
            #mpl_lib.tune_xy_lim(axes)
            if i==0 and j==0:  rm_inner(axes[1:])
            else: rm_inner(axes)

        deco(figs_p.axes[0],iopt=6,hkl=hkl)

        mpl_lib.tune_xy_lim(figs_p.axes)
        #print 'no'
        ticks_bin_u(figs_p.axes,n=3)

        if ylim!=None:
            for i in xrange(len(figs_p.axes)):
                figs_p.axes[i].set_ylim(ylim)

        if iopt==1:
            for i in xrange(len(figs.axes)):
                figs.axes[i].set_xlim(0.0,0.5)
            for i in xrange(3):
                figs.axes[i].set_ylim(-2,2)
                figs.axes[3+i].set_ylim(0.,0.1)
        plt.draw();plt.show()
Esempio n. 8
0
    def plot(self, nbin_sin2psi=2, iopt=0, ylim=None, mxnphi=None, hkl='211'):
        """
        Arguments
        =========
        nbin_sin2psi = 2
        iopt         = iopt
        ylim         = None
        mxnphi       = None
        hkl          = '211'
        """
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        import matplotlib.pyplot as plt
        if hasattr(self, 'vf'):
            nh = 3
        else:
            nh = 2

        if type(mxnphi) == type(None): mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi, nh=nh, w0=0, w1=0, left=0.2, right=0.15)
        mx = max(self.flow.epsilon_vm)
        mn = min(self.flow.epsilon_vm)
        #mx = 1.
        #mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)
        colors = []
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i == 0: colors.append(cl)

                y = self.sf[j, i, :, 0].copy() * 1e12
                l, = figs.axes[i].plot(np.sign(self.psi) *
                                       sin(self.psi * np.pi / 180.)**2,
                                       y,
                                       '-x',
                                       color=cl)
                y = self.sf[j, i, :, 1].copy() * 1e12
                figs.axes[i + mxnphi].plot(np.sign(self.psi) *
                                           sin(self.psi * np.pi / 180.)**2,
                                           y,
                                           '-+',
                                           color=cl)

                if j == 0:
                    figs.axes[i].set_title(r'$\phi: %3.1f^\circ{}$' %
                                           self.phi[i])

        if nh == 3:
            for i in xrange(mxnphi):
                for j in xrange(self.flow.nstp):
                    eps = self.flow.epsilon_vm[j]
                    cl = c.to_rgba(eps)
                    y = self.vf[j, i, :]
                    figs.axes[i + mxnphi * 2].plot(
                        np.sign(self.psi) * sin(self.psi * np.pi / 180.)**2,
                        y,
                        '-',
                        color=cl)

        deco = axes_label.__deco__
        rm_inner = mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u
        rm_inner(figs.axes[:mxnphi * 2])
        if nh == 3: rm_inner(figs.axes[mxnphi * 2:mxnphi * 3])
        deco(figs.axes[0], iopt=1, ipsi_opt=1, hkl=hkl)
        if nh == 3: deco(figs.axes[mxnphi * 2], iopt=7, ipsi_opt=1, hkl=hkl)
        mpl_lib.tune_xy_lim(figs.axes[:mxnphi * 2])
        if ylim != None:
            for i in xrange(len(figs.axes[:mxnphi * 2])):
                figs.axes[i].set_ylim(ylim)
        if nh == 3: mpl_lib.tune_xy_lim(figs.axes[mxnphi * 2:mxnphi * 3])
        ticks_bin_u(figs.axes[:mxnphi * 2], n=4)
        if nh == 3: ticks_bin_u(figs.axes[mxnphi * 2:mxnphi * 3], n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])
        mpl_lib.add_cb(ax=axcb,
                       filled=False,
                       norm=norm,
                       levels=self.flow.epsilon_vm,
                       format='%5.3f',
                       colors=colors,
                       ylab='Equivalent strain')

        if nh == 1 or nh == 2: return
        """   SF(phi,psi) vs plastic strain   """
        ## binning sin2psi
        nbin = nbin_sin2psi
        indx = self.__binning__(nbin=nbin, mx=0.5)

        for i in xrange(len(indx)):
            print '%i bin' % (i + 1)
            for j in xrange(len(indx[i])):
                print '%4i' % indx[i][j],
                print '%4.2f' % (self.sin2psi[indx[i][j]]),
            print

        if mxnphi != None: mxnphi = self.nphi
        figs_p = wide_fig(nw=mxnphi, nh=nbin, w0=0, w1=0, left=0.2, right=0.15)

        eps = self.flow.epsilon_vm
        for i in xrange(mxnphi):
            for j in xrange(nbin):
                ax = figs_p.axes[i + mxnphi * j]
                if j == nbin - 1:
                    ax.set_title(r'$\phi: %3.1f^\circ{}$' % self.phi[i])
                idx = indx[j]
                for k in xrange(len(idx)):
                    y = self.sf[:, i, [idx[k]], 0][::]
                    ax.plot(eps, y, 'x')

        for i in xrange(nbin):
            axes = []
            for j in xrange(mxnphi * 2):
                axes.append(figs_p.axes[j + mxnphi * i])
            #mpl_lib.tune_xy_lim(axes)
            if i == 0 and j == 0: rm_inner(axes[1:])
            else: rm_inner(axes)

        deco(figs_p.axes[0], iopt=6, hkl=hkl)

        mpl_lib.tune_xy_lim(figs_p.axes)
        #print 'no'
        ticks_bin_u(figs_p.axes, n=3)

        if ylim != None:
            for i in xrange(len(figs_p.axes)):
                figs_p.axes[i].set_ylim(ylim)

        if iopt == 1:
            for i in xrange(len(figs.axes)):
                figs.axes[i].set_xlim(0.0, 0.5)
            for i in xrange(3):
                figs.axes[i].set_ylim(-2, 2)
                figs.axes[3 + i].set_ylim(0., 0.1)
        plt.draw()
        plt.show()