ribolands/plotting.py
def plot_nxy(name, tfile,
             title = '',
             plim = 1e-2,
             lines = [],
             xscale = 'log',
             ylim = None,
             xlim = None):
    """ Plot a list of trajectories.

    Args:
      name (str): Name of the pdf file.
      tfile (str): Filename of a treekin `nxy` output file.
      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.
      xscale (str, optional): *lin* or *log*. Default: *log*.
      xlim ((float,float), optional): matplotlib xlim.
      ylim ((float,float), optional): matplotlib ylim.

    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
            nxy.append(list(map(float, line.strip().split())))

    # Do the plotting
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.spines['right'].set_visible(False)
    ax.set_xscale(xscale)

    if ylim: ax.set_ylim(ylim)
    if xlim: ax.set_xlim(xlim)

    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 = 1.5)
        p.set_label("ID {:d}".format(e))

    fig.set_size_inches(7, 3)
    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)

    # Add ticks for 1 minute, 1 hour, 1 day, 1 year
    #ax.axvline(x = 60, linewidth = 1, color = 'black', linestyle = '--') # 1 minute
    #ax.axvline(x = 3600, linewidth = 1, color = 'black', linestyle = '--') # 1 hour
    #ax.axvline(x = 86400, linewidth = 1, color = 'black', linestyle = '--') # 1 day
    #ax.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.
      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.
      xscale (str, optional): *lin* or *log*. Default: *log*.
      xlim ((float,float), optional): matplotlib xlim.
      ylim ((float,float), optional): matplotlib ylim.

    Returns:
      [str]: Name of the output file.
    
Plot a list of trajectories.
Plot a list of trajectories .
def plot_nxy(name, tfile,
             title = '',
             plim = 1e-2,
             lines = [],
             xscale = 'log',
             ylim = None,
             xlim = None):
    lines = set(lines)
    title = title if title else name
    nxy = []
    with open(tfile) as tkn:
        for line in tkn:
            if re.match('#', line):
                continue
            nxy.append(list(map(float, line.strip().split())))
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.spines['right'].set_visible(False)
    ax.set_xscale(xscale)
    if ylim: ax.set_ylim(ylim)
    if xlim: ax.set_xlim(xlim)
    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 = 1.5)
        p.set_label("ID {:d}".format(e))
    fig.set_size_inches(7, 3)
    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)
    plt.legend()
    plt.savefig(name, bbox_inches='tight')
    plt.close()
    return name
def plot_nxy ( name , tfile , title = '' , plim = 1e-2 , lines = [ ] , xscale = 'log' , ylim = None , xlim = None ) : lines = set ( lines ) title = title if title else name nxy = [ ] with open ( tfile ) as tkn : for line in tkn : if re . match ( '#' , line ) : continue nxy . append ( list ( map ( float , line . strip ( ) . split ( ) ) ) ) fig = plt . figure ( ) ax = fig . add_subplot ( 1 , 1 , 1 ) ax . spines [ 'right' ] . set_visible ( False ) ax . set_xscale ( xscale ) if ylim : ax . set_ylim ( ylim ) if xlim : ax . set_xlim ( xlim ) 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 = 1.5 ) p . set_label ( "ID {:d}" . format ( e ) ) fig . set_size_inches ( 7 , 3 ) 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 ) 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.
      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.
      xscale (str, optional): *lin* or *log*. Default: *log*.
      xlim ((float,float), optional): matplotlib xlim.
      ylim ((float,float), optional): matplotlib ylim.

    Returns:
      [str]: Name of the output file.
    """ # Do the plotting # Add ticks for 1 minute, 1 hour, 1 day, 1 year #ax.axvline(x = 60, linewidth = 1, color = 'black', linestyle = '--') # 1 minute #ax.axvline(x = 3600, linewidth = 1, color = 'black', linestyle = '--') # 1 hour #ax.axvline(x = 86400, linewidth = 1, color = 'black', linestyle = '--') # 1 day #ax.axvline(x = 31536000, linewidth = 1, color = 'black', linestyle = '--') # 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 .
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 .
xscale
lin* or *log*. Default: *log*.
lin * or * log * . Default : * log * .
ylim
None
xlim
None