Exemplo n.º 1
0
def draw_v(y_val, job, title, xtitle, ytitle, Lsave,yscale):
    job_title=get_jobtitle(job,title, xtitle, ytitle)

    if job == 'eda':
        if yscale:
            ys = np.array(yscale) * j2cal
    x=Ni_6x
    y=np.array(y_val)*ys
    mplot_nvector(x, y, Title=job_title.title, Xtitle=job_title.xtitle, Ytitle=job_title.ytitle, Lsave=Lsave)
    
    return 0
Exemplo n.º 2
0
def draw_twinx(fs,icx,x_val,icy,job,title,xt,yt,yl,Lsave,yscale,colors):
    """
    This works for several files with only one y-value
    if x is included in file, modify
    if 1st line is label, modify
    """
    if title:
        tag_title=1
    else:
        job_title=get_jobtitle(job,title, xt, yt)
        tag_title=0

    if len(fs) != 1:
        if yl:
            if len(fs) != len(yl):
                print("Input y-label accurately")
                sys.exit(1)
        else:
            yl=[]
            for f in fs:
                pre, _ = fname_decom(f)
                yl.append(pre)

    y_2d=[]
    for f1 in fs:
        with open(f1,"r") as f:
            lines=f.readlines()
            x = []     
            y_val = []     # y as 2d [ [y1], [y2], ...] 
            i = 0
            for line in lines:
                items = line.strip().split()
                if items:
                
                    if icx:
                        x.append(float(items[icx-1]))
                    #y_line = []     # convert string to float for a list
                    if icy:
                        pass
                    ### one y-value for a file
                    else:
                    #for y in icy:
                        #y_line.append(float(items[y-1]))    # make 1D array
                        #print(f"{y} {items[y-1]}")
                        #y_val.append(float(items[y-1]))    # make 1D array
                        y_val.append(float(items[0]))    # make 1D array
                        #y.append(y_line)                # make 2D array
                i+=1
            y_2d.append(y_val)
    if not x:
        if x_val:
            x = x_val
        else:
            x=Ni_6x
    #x=Ni_6x
    ### y.ndim can be 1 or 2
    print(f'length of x: {len(x)}')
    if len(fs) == 1:
        y = y_val
    else:
        y = y_2d
    #yscale = get_yv_scale(yscale)           # get_yv_scale returns list
    yscale=[0.01,0.01,1.0]
    y=np.array(y)*np.array(yscale)[:,None]
    print("before draw mplot_twinx")
    print(f"{x} ")
    if tag_title:
        print(f"title = {title} xt = {xt}")
        mplot_twinx(x, y, Title=title, Xtitle=xt, Ytitle=yt, Lsave=Lsave,Ylabels=yl, Colors=colors)
    else:
        mplot_twinx(x, y, Title=job_title.title, Xtitle=job_title.xtitle, Ytitle=job_title.ytitle, Lsave=Lsave,Ylabels=yl,Colors=colors)
    return 0
Exemplo n.º 3
0
def draw_f(fs, icx, x_col, icy, job, title, xt, yt, yl, Lsave, yscale, colors,
           Ltwinx):
    if x_col:
        x = Ni_6x
    else:
        x = []
    if title:
        tag_title = 1
    else:
        job_title = get_jobtitle(job, title, xt, yt)
        tag_title = 0

    if len(fs) == 1:
        if not yl:
            yl = []
    else:
        if yl:
            if len(fs) != len(yl):
                print("Input y-label accurately")
                sys.exit(1)
        else:
            yl = []
            for f in fs:
                pre, _ = fname_decom(f)
                yl.append(pre)

    y_2d = []
    for f1 in fs:
        with open(f1, "r") as f:
            lines = f.readlines()
            x_val = []
            y_val = []  # y as 2d [ [y1], [y2], ...]
            i = 0
            for line in lines:
                ### if 1 file with labels, obtain yl
                if i == 0:
                    ### if there is character, read labels
                    if parsing.is_there_char(line.strip()):
                        items = line.strip().split()
                        ncol = len(items)
                        if not icx:
                            icx = 1
                            print(f"use icx {icx}")
                        x_title = items.pop(icx - 1)
                        if not xt:
                            xt = x_title
                        if not yl:
                            for item in items:
                                yl.append(item)
                        if not icy:
                            icy = [x for x in range(2, ncol + 1)]
                            print(f"use icy {icy}")
                        i += 1
                        continue
                ### read data line from file
                items = line.strip().split()
                if items:
                    if icx:
                        x.append(float(items[icx - 1]))
                        #x_value.append(float(items[icx-1]))
                    #y_line = []     # convert string to float for a list
                    for y in icy:
                        #y_line.append(float(items[y-1]))    # make 1D array
                        #print(f"{y} {items[y-1]}")
                        y_val.append(float(items[y - 1]))  # make 1D array
                        #y.append(y_line)                # make 2D array
                i += 1
            ### y_2d: 1 y_val, nfiles
            ###       n y_val, 1 files
            y_2d.append(y_val)
            #y_nfile.append(y_val)
    ### y.ndim can be 1 or 2
    if len(fs) == 1:
        ### if 1 y_val
        #y = y_val
        ### if n y_val
        print(f"size of y: {len(yl)}")
        ndata = len(y_2d[0])
        nrow = ndata / ncol
        new_array = np.array(y_2d[0]).reshape(-1, len(yl))
        print(f"shape of y-data {new_array.shape}")
        y = [*zip(*new_array)]
        print(f"shape of y-data {np.array(y).shape}")
    else:
        y = y_2d
    ### scaling with 0-th axis: y shape was ready for [y1, y2, ...,yn]
    ### scaling canbe *|+ for view in plot
    #yscale = get_yv_scale(yscale)
    yscale = [4158.65, 4158.65, 0]
    y = np.array(y) + np.array(yscale)[:, None]
    if tag_title:
        print(f"title = {title} xt = {xt}")
        mplot_nvector(x,
                      y,
                      Title=title,
                      Xtitle=xt,
                      Ytitle=yt,
                      Lsave=Lsave,
                      Ylabels=yl,
                      Colors=colors,
                      Ltwinx=Ltwinx)
    else:
        mplot_nvector(x,
                      y,
                      Title=job_title.title,
                      Xtitle=job_title.xtitle,
                      Ytitle=job_title.ytitle,
                      Lsave=Lsave,
                      Ylabels=yl,
                      Colors=colors,
                      Ltwinx=Ltwinx)
    return 0