ribolands/plotting.py
def plot_nxy_linlog(name, tfile,
             xlim,
             title = '',
             plim = 1e-2,
             lines = [],
             ylim = None,
             figwidth = 7,
             figheight = 3,
             figdivide = 3.5):
    """ Plot a list of trajectories.

    Args:
      name (str): Name of the pdf file.
      tfile (str): Filename of a treekin `nxy` output file.
      xlim (float, float, float): Time poins for start, 
        lin-to-log switch and end.
      title (str, optional): Name of the title for the plot.
      plim (float, optional): Minimal occupancy to plot a trajectory. Defaults to 0.01
      lines ([int,..], optional): Selected list of lines to be plotted.
      ylim ((float,float), optional): matplotlib xlim.
      figdivide(float, optional): Set the size of the log-part of the plot.

    Returns:
      [str]: Name of the output file.
    """

    lines = set(lines)
    title = title if title else name

    nxy = []
    with open(tfile) as tkn:
        for line in tkn:
            if re.match('#', line):
                continue
            tr = list(map(float, line.strip().split()))
            maxtime = tr[0]
            nxy.append(tr)

    # Get the relevant arguments from args
    lintime = xlim[1]
    logtime = max(xlim[2] - lintime, lintime * 10)
    
    # Do the plotting
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.spines['right'].set_visible(False)
    if ylim:
        ax.set_ylim(ylim)
        #ax.set_ylim([-0.05, 1.05])
    ax.set_xscale('linear')

    # Make the second part of the plot logarithmic
    offset = 0.00001
    ax.set_xlim((xlim[0], xlim[1] + offset))
    divider = make_axes_locatable(ax)
    axLog = divider.append_axes("right", size = figdivide, pad = 0, sharey = ax)
    axLog.set_xscale('log')
    axLog.set_xlim((xlim[1] + offset, logtime))
    if ylim:
        ax.set_ylim(ylim)
        #ax.set_ylim([-0.05, 1.05])
    axLog.yaxis.set_visible(False)
    axLog.spines['left'].set_visible(False)

    for e, traject in enumerate(zip(*nxy)):
        if e == 0:
            time = traject
            continue
        if lines and e not in lines:
            continue
        if plim and max(traject) < plim:
            continue
        p, = ax.plot(time, traject, '-', lw = 0.5)
        L, = axLog.plot(time, traject, '-', lw = 0.5)
        L.set_label("ID {:d}".format(e))

    fig.set_size_inches(figwidth, figheight)
    fig.text(0.5, 0.95, title, ha='center', va='center')
    ax.set_ylabel('occupancy', fontsize = 11)
    ax.set_xlabel('time [s]', ha = 'center', va = 'center', fontsize = 11)
    ax.xaxis.set_label_coords(.9, -0.2)

    # Add ticks for 1 minute, 1 hour, 1 day, 1 year
    axLog.axvline(x = lintime, linewidth = 3, color = 'black', linestyle = '-') 
    axLog.axvline(x = 60, linewidth = 1, color = 'black', linestyle = '--') # 1 minute
    axLog.axvline(x = 3600, linewidth = 1, color = 'black', linestyle = '--') # 1 hour
    axLog.axvline(x = 86400, linewidth = 1, color = 'black', linestyle = '--') # 1 day
    axLog.axvline(x = 31536000, linewidth = 1, color = 'black', linestyle = '--') # 1 year
    plt.legend()

    plt.savefig(name, bbox_inches='tight')
    plt.close()
    return name
 Plot a list of trajectories.

    Args:
      name (str): Name of the pdf file.
      tfile (str): Filename of a treekin `nxy` output file.
      xlim (float, float, float): Time poins for start, 
        lin-to-log switch and end.
      title (str, optional): Name of the title for the plot.
      plim (float, optional): Minimal occupancy to plot a trajectory. Defaults to 0.01
      lines ([int,..], optional): Selected list of lines to be plotted.
      ylim ((float,float), optional): matplotlib xlim.
      figdivide(float, optional): Set the size of the log-part of the plot.

    Returns:
      [str]: Name of the output file.
    
Plot a list of trajectories.
Plot a list of trajectories .
def plot_nxy_linlog(name, tfile,
             xlim,
             title = '',
             plim = 1e-2,
             lines = [],
             ylim = None,
             figwidth = 7,
             figheight = 3,
             figdivide = 3.5):
    lines = set(lines)
    title = title if title else name
    nxy = []
    with open(tfile) as tkn:
        for line in tkn:
            if re.match('#', line):
                continue
            tr = list(map(float, line.strip().split()))
            maxtime = tr[0]
            nxy.append(tr)
    lintime = xlim[1]
    logtime = max(xlim[2] - lintime, lintime * 10)
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.spines['right'].set_visible(False)
    if ylim:
        ax.set_ylim(ylim)
    ax.set_xscale('linear')
    offset = 0.00001
    ax.set_xlim((xlim[0], xlim[1] + offset))
    divider = make_axes_locatable(ax)
    axLog = divider.append_axes("right", size = figdivide, pad = 0, sharey = ax)
    axLog.set_xscale('log')
    axLog.set_xlim((xlim[1] + offset, logtime))
    if ylim:
        ax.set_ylim(ylim)
    axLog.yaxis.set_visible(False)
    axLog.spines['left'].set_visible(False)
    for e, traject in enumerate(zip(*nxy)):
        if e == 0:
            time = traject
            continue
        if lines and e not in lines:
            continue
        if plim and max(traject) < plim:
            continue
        p, = ax.plot(time, traject, '-', lw = 0.5)
        L, = axLog.plot(time, traject, '-', lw = 0.5)
        L.set_label("ID {:d}".format(e))
    fig.set_size_inches(figwidth, figheight)
    fig.text(0.5, 0.95, title, ha='center', va='center')
    ax.set_ylabel('occupancy', fontsize = 11)
    ax.set_xlabel('time [s]', ha = 'center', va = 'center', fontsize = 11)
    ax.xaxis.set_label_coords(.9, -0.2)
    axLog.axvline(x = lintime, linewidth = 3, color = 'black', linestyle = '-') 
    axLog.axvline(x = 60, linewidth = 1, color = 'black', linestyle = '--') 
    axLog.axvline(x = 3600, linewidth = 1, color = 'black', linestyle = '--') 
    axLog.axvline(x = 86400, linewidth = 1, color = 'black', linestyle = '--') 
    axLog.axvline(x = 31536000, linewidth = 1, color = 'black', linestyle = '--') 
    plt.legend()
    plt.savefig(name, bbox_inches='tight')
    plt.close()
    return name
def plot_nxy_linlog ( name , tfile , xlim , title = '' , plim = 1e-2 , lines = [ ] , ylim = None , figwidth = 7 , figheight = 3 , figdivide = 3.5 ) : lines = set ( lines ) title = title if title else name nxy = [ ] with open ( tfile ) as tkn : for line in tkn : if re . match ( '#' , line ) : continue tr = list ( map ( float , line . strip ( ) . split ( ) ) ) maxtime = tr [ 0 ] nxy . append ( tr ) lintime = xlim [ 1 ] logtime = max ( xlim [ 2 ] - lintime , lintime * 10 ) fig = plt . figure ( ) ax = fig . add_subplot ( 1 , 1 , 1 ) ax . spines [ 'right' ] . set_visible ( False ) if ylim : ax . set_ylim ( ylim ) ax . set_xscale ( 'linear' ) offset = 0.00001 ax . set_xlim ( ( xlim [ 0 ] , xlim [ 1 ] + offset ) ) divider = make_axes_locatable ( ax ) axLog = divider . append_axes ( "right" , size = figdivide , pad = 0 , sharey = ax ) axLog . set_xscale ( 'log' ) axLog . set_xlim ( ( xlim [ 1 ] + offset , logtime ) ) if ylim : ax . set_ylim ( ylim ) axLog . yaxis . set_visible ( False ) axLog . spines [ 'left' ] . set_visible ( False ) for e , traject in enumerate ( zip ( * nxy ) ) : if e == 0 : time = traject continue if lines and e not in lines : continue if plim and max ( traject ) < plim : continue p , = ax . plot ( time , traject , '-' , lw = 0.5 ) L , = axLog . plot ( time , traject , '-' , lw = 0.5 ) L . set_label ( "ID {:d}" . format ( e ) ) fig . set_size_inches ( figwidth , figheight ) fig . text ( 0.5 , 0.95 , title , ha = 'center' , va = 'center' ) ax . set_ylabel ( 'occupancy' , fontsize = 11 ) ax . set_xlabel ( 'time [s]' , ha = 'center' , va = 'center' , fontsize = 11 ) ax . xaxis . set_label_coords ( .9 , - 0.2 ) axLog . axvline ( x = lintime , linewidth = 3 , color = 'black' , linestyle = '-' ) axLog . axvline ( x = 60 , linewidth = 1 , color = 'black' , linestyle = '--' ) axLog . axvline ( x = 3600 , linewidth = 1 , color = 'black' , linestyle = '--' ) axLog . axvline ( x = 86400 , linewidth = 1 , color = 'black' , linestyle = '--' ) axLog . axvline ( x = 31536000 , linewidth = 1 , color = 'black' , linestyle = '--' ) plt . legend ( ) plt . savefig ( name , bbox_inches = 'tight' ) plt . close ( ) return name
Plot a list of trajectories.
Plot a list of trajectories .
""" Plot a list of trajectories.

    Args:
      name (str): Name of the pdf file.
      tfile (str): Filename of a treekin `nxy` output file.
      xlim (float, float, float): Time poins for start, 
        lin-to-log switch and end.
      title (str, optional): Name of the title for the plot.
      plim (float, optional): Minimal occupancy to plot a trajectory. Defaults to 0.01
      lines ([int,..], optional): Selected list of lines to be plotted.
      ylim ((float,float), optional): matplotlib xlim.
      figdivide(float, optional): Set the size of the log-part of the plot.

    Returns:
      [str]: Name of the output file.
    """ # Get the relevant arguments from args # Do the plotting #ax.set_ylim([-0.05, 1.05]) # Make the second part of the plot logarithmic #ax.set_ylim([-0.05, 1.05]) # Add ticks for 1 minute, 1 hour, 1 day, 1 year # 1 minute # 1 hour # 1 day # 1 year
Name of the output file.
Name of the output file .
[str]
name
Name of the pdf file.
Name of the pdf file .
tfile
Filename of a treekin `nxy` output file.
Filename of a treekin ` nxy ` output file .
xlim
Time poins for start,
lin-to-log switch and end.
Time poins for start lin - to - log switch and end .
title
Name of the title for the plot.
Name of the title for the plot .
plim
Minimal occupancy to plot a trajectory. Defaults to 0.01
Minimal occupancy to plot a trajectory . Defaults to 0 . 01
0
lines
Selected list of lines to be plotted.
Selected list of lines to be plotted .
ylim
None
figwidth
figheight
figdivide
Set the size of the log-part of the plot.
Set the size of the log - part of the plot .