sidpy/viz/plot_utils/curve.py
def plot_line_family(axis, x_vec, line_family, line_names=None, label_prefix='', label_suffix='',
                     y_offset=0, show_cbar=False, **kwargs):
    """
    Plots a family of lines with a sequence of colors

    Parameters
    ----------
    axis : matplotlib.axes.Axes object
        Axis to plot the curve
    x_vec : array-like
        Values to plot against
    line_family : 2D numpy array
        family of curves arranged as [curve_index, features]
    line_names : array-like
        array of string or numbers that represent the identity of each curve in the family
    label_prefix : string / unicode
        prefix for the legend (before the index of the curve)
    label_suffix : string / unicode
        suffix for the legend (after the index of the curve)
    y_offset : (optional) number
        quantity by which the lines are offset from each other vertically (useful for spectra)
    show_cbar : (optional) bool
        Whether or not to show a colorbar (instead of a legend)

    """
    if not isinstance(axis, mpl.axes.Axes):
        raise TypeError('axis must be a matplotlib.axes.Axes object')
    if not isinstance(x_vec, (list, tuple, np.ndarray, da.core.Array)):
        raise TypeError('x_vec must be array-like of numbers')
    x_vec = np.array(x_vec)
    assert x_vec.ndim == 1, 'x_vec must be a 1D array'
    if not isinstance(line_family, list):
        line_family = np.array(line_family)
    if not isinstance(line_family, (np.ndarray, da.core.Array)):
        raise TypeError('line_family must be a 2d array of numbers')
    assert line_family.ndim == 2, 'line_family must be a 2D array'
    #    assert x_vec.shape[1] == line_family.shape[1], \
    #        'The size of the 2nd dimension of line_family must match with of x_vec, but line fam has shape {} whereas xvec has shape {}'.format(line_family.shape, x_vec.shape)
    num_lines = line_family.shape[0]
    for var, var_name in zip([label_suffix, label_prefix], ['label_suffix', 'label_prefix']):
        if not isinstance(var, (str, unicode)):
            raise TypeError(var_name + ' needs to be a string')
    if not isinstance(y_offset, Number):
        raise TypeError('y_offset should be a Number')
    assert isinstance(show_cbar, bool)
    if line_names is not None:
        if not isinstance(line_names, (list, tuple)):
            raise TypeError('line_names should be a list of strings')
        if not np.all([isinstance(x, (str, unicode)) for x in line_names]):
            raise TypeError('line_names should be a list of strings')
        if len(line_names) != num_lines:
            raise ValueError('length of line_names not matching with that of line_family')

    cmap = get_cmap_object(kwargs.pop('cmap', None))

    if line_names is None:
        # label_prefix = 'Line '
        line_names = [str(line_ind) for line_ind in range(num_lines)]

    line_names = ['{} {} {}'.format(label_prefix, cur_name, label_suffix) for cur_name in line_names]

    for line_ind in range(num_lines):
        axis.plot(x_vec, line_family[line_ind] + line_ind * y_offset,
                  label=line_names[line_ind],
                  color=cmap(int(255 * line_ind / (num_lines ))), **kwargs)

    if show_cbar:
        # put back the cmap parameter:
        kwargs.update({'cmap': cmap})
        _ = cbar_for_line_plot(axis, num_lines, **kwargs)

    Plots a family of lines with a sequence of colors

    Parameters
    ----------
    axis : matplotlib.axes.Axes object
        Axis to plot the curve
    x_vec : array-like
        Values to plot against
    line_family : 2D numpy array
        family of curves arranged as [curve_index, features]
    line_names : array-like
        array of string or numbers that represent the identity of each curve in the family
    label_prefix : string / unicode
        prefix for the legend (before the index of the curve)
    label_suffix : string / unicode
        suffix for the legend (after the index of the curve)
    y_offset : (optional) number
        quantity by which the lines are offset from each other vertically (useful for spectra)
    show_cbar : (optional) bool
        Whether or not to show a colorbar (instead of a legend)

    
Plots a family of lines with a sequence of colors
Parameters


Plots a family of lines with a sequence of colors Parameters
def plot_line_family(axis, x_vec, line_family, line_names=None, label_prefix='', label_suffix='',
                     y_offset=0, show_cbar=False, **kwargs):
    if not isinstance(axis, mpl.axes.Axes):
        raise TypeError('axis must be a matplotlib.axes.Axes object')
    if not isinstance(x_vec, (list, tuple, np.ndarray, da.core.Array)):
        raise TypeError('x_vec must be array-like of numbers')
    x_vec = np.array(x_vec)
    assert x_vec.ndim == 1, 'x_vec must be a 1D array'
    if not isinstance(line_family, list):
        line_family = np.array(line_family)
    if not isinstance(line_family, (np.ndarray, da.core.Array)):
        raise TypeError('line_family must be a 2d array of numbers')
    assert line_family.ndim == 2, 'line_family must be a 2D array'
    num_lines = line_family.shape[0]
    for var, var_name in zip([label_suffix, label_prefix], ['label_suffix', 'label_prefix']):
        if not isinstance(var, (str, unicode)):
            raise TypeError(var_name + ' needs to be a string')
    if not isinstance(y_offset, Number):
        raise TypeError('y_offset should be a Number')
    assert isinstance(show_cbar, bool)
    if line_names is not None:
        if not isinstance(line_names, (list, tuple)):
            raise TypeError('line_names should be a list of strings')
        if not np.all([isinstance(x, (str, unicode)) for x in line_names]):
            raise TypeError('line_names should be a list of strings')
        if len(line_names) != num_lines:
            raise ValueError('length of line_names not matching with that of line_family')
    cmap = get_cmap_object(kwargs.pop('cmap', None))
    if line_names is None:
        line_names = [str(line_ind) for line_ind in range(num_lines)]
    line_names = ['{} {} {}'.format(label_prefix, cur_name, label_suffix) for cur_name in line_names]
    for line_ind in range(num_lines):
        axis.plot(x_vec, line_family[line_ind] + line_ind * y_offset,
                  label=line_names[line_ind],
                  color=cmap(int(255 * line_ind / (num_lines ))), **kwargs)
    if show_cbar:
        kwargs.update({'cmap': cmap})
        _ = cbar_for_line_plot(axis, num_lines, **kwargs)
def plot_line_family ( axis , x_vec , line_family , line_names = None , label_prefix = '' , label_suffix = '' , y_offset = 0 , show_cbar = False , ** kwargs ) : if not isinstance ( axis , mpl . axes . Axes ) : raise TypeError ( 'axis must be a matplotlib.axes.Axes object' ) if not isinstance ( x_vec , ( list , tuple , np . ndarray , da . core . Array ) ) : raise TypeError ( 'x_vec must be array-like of numbers' ) x_vec = np . array ( x_vec ) assert x_vec . ndim == 1 , 'x_vec must be a 1D array' if not isinstance ( line_family , list ) : line_family = np . array ( line_family ) if not isinstance ( line_family , ( np . ndarray , da . core . Array ) ) : raise TypeError ( 'line_family must be a 2d array of numbers' ) assert line_family . ndim == 2 , 'line_family must be a 2D array' num_lines = line_family . shape [ 0 ] for var , var_name in zip ( [ label_suffix , label_prefix ] , [ 'label_suffix' , 'label_prefix' ] ) : if not isinstance ( var , ( str , unicode ) ) : raise TypeError ( var_name + ' needs to be a string' ) if not isinstance ( y_offset , Number ) : raise TypeError ( 'y_offset should be a Number' ) assert isinstance ( show_cbar , bool ) if line_names is not None : if not isinstance ( line_names , ( list , tuple ) ) : raise TypeError ( 'line_names should be a list of strings' ) if not np . all ( [ isinstance ( x , ( str , unicode ) ) for x in line_names ] ) : raise TypeError ( 'line_names should be a list of strings' ) if len ( line_names ) != num_lines : raise ValueError ( 'length of line_names not matching with that of line_family' ) cmap = get_cmap_object ( kwargs . pop ( 'cmap' , None ) ) if line_names is None : line_names = [ str ( line_ind ) for line_ind in range ( num_lines ) ] line_names = [ '{} {} {}' . format ( label_prefix , cur_name , label_suffix ) for cur_name in line_names ] for line_ind in range ( num_lines ) : axis . plot ( x_vec , line_family [ line_ind ] + line_ind * y_offset , label = line_names [ line_ind ] , color = cmap ( int ( 255 * line_ind / ( num_lines ) ) ) , ** kwargs ) if show_cbar : kwargs . update ( { 'cmap' : cmap } ) _ = cbar_for_line_plot ( axis , num_lines , ** kwargs )
Plots a family of lines with a sequence of colors
Parameters
Plots a family of lines with a sequence of colors Parameters
"""
    Plots a family of lines with a sequence of colors

    Parameters
    ----------
    axis : matplotlib.axes.Axes object
        Axis to plot the curve
    x_vec : array-like
        Values to plot against
    line_family : 2D numpy array
        family of curves arranged as [curve_index, features]
    line_names : array-like
        array of string or numbers that represent the identity of each curve in the family
    label_prefix : string / unicode
        prefix for the legend (before the index of the curve)
    label_suffix : string / unicode
        suffix for the legend (after the index of the curve)
    y_offset : (optional) number
        quantity by which the lines are offset from each other vertically (useful for spectra)
    show_cbar : (optional) bool
        Whether or not to show a colorbar (instead of a legend)

    """ #    assert x_vec.shape[1] == line_family.shape[1], \ #        'The size of the 2nd dimension of line_family must match with of x_vec, but line fam has shape {} whereas xvec has shape {}'.format(line_family.shape, x_vec.shape) # label_prefix = 'Line ' # put back the cmap parameter:
axis
x_vec
line_family
line_names
label_prefix
label_suffix
y_offset
show_cbar