Generic function for plotting any kind of MRS data. Uses matplotlib's pyplot for plotting
    but automatically applies MRS-data specific formatting parameters. 
    
    Parameters
    ----------
    xdata : array_like
            Data to plot on x-axis
    ydata : array_like
            Data to plot on y-axis
    plot_type : string-optional
                Type of plot to generate. Determines some default plotting parameters, if they are specified.
                Currently implemented: ['spectrum', 'fids']
    plot_params : dictionary-optional
                  Dictionary of parameters to use for generating the graph and formatting the axes. 
                  If plot_params = {}, default parameters are used.
    ax : axis handle-optional
                   If not empty, add the plot to this axis, instead of generating a new figure + axis
                  
    Returns
    -------
    fig_handle : figure handle
                Handle of the figure the data was added to
    line_handles : 2D line object handle(s)
                    List of handles to each of the line objects added to the current axis
    ax : axes handle
                   Handle of the axes data was added to

def plot(xdata, ydata, plot_type='', plot_params={}, ax=None):
    """
    Generic function for plotting any kind of MRS data. Uses matplotlib's pyplot for plotting
    but automatically applies MRS-data specific formatting parameters. 
    
    Parameters
    ----------
    xdata : array_like
            Data to plot on x-axis
    ydata : array_like
            Data to plot on y-axis
    plot_type : string-optional
                Type of plot to generate. Determines some default plotting parameters, if they are specified.
                Currently implemented: ['spectrum', 'fids']
    plot_params : dictionary-optional
                  Dictionary of parameters to use for generating the graph and formatting the axes. 
                  If plot_params = {}, default parameters are used.
    ax : axis handle-optional
                   If not empty, add the plot to this axis, instead of generating a new figure + axis
                  
    Returns
    -------
    fig_handle : figure handle
                Handle of the figure the data was added to
    line_handles : 2D line object handle(s)
                    List of handles to each of the line objects added to the current axis
    ax : axes handle
                   Handle of the axes data was added to
     
    """
    import numpy as np
    from cycler import cycler
    import matplotlib.pyplot as plt
   
    
    # Check on the shape of the input data
    if ydata.shape[0] != xdata.shape[0] and ydata.shape[1] != xdata.shape[0]:
        # Throw an error
        pass
    elif ydata.shape[0] != xdata.shape[0]:
        # Transpose the data
        ydata = ydata.T

        
    # Get the plot parameters. Start with defaults, and then update to include any 
    # changes passed in to the function
    params = get_default_plot_params(plot_type)
    params.update(plot_params)

    if ax is None:
        if params['suppress_fig']:
            # Suppress drawing the figure
            plt.ioff()
        fig_handle=plt.figure(figsize=params['figsize'],facecolor='w')  
        ax = fig_handle.add_subplot(1,1,1)

    # Set the color order cycle that will be applied to any lines added to the current axis        
    ax.set_prop_cycle(cycler('color',params['color_order']))
    
    if params['use_colormap'] and len(ydata.shape)>1:
        # Override the color order using the specified color map
        # Distribute colormap colors evenly spaced for all the lines in the plot
    
        # Get the colors from the selected colormap to use for color cycling
        cmap = plt.get_cmap(params['colormap'])
        co = [cmap(ii) for ii in np.linspace(0.0,0.9,ydata.shape[1])]  
        ax.set_prop_cycle(cycler('color',co))
    
    #Add data to the axis    
    ax.plot(xdata,ydata)  

    # Apply the plot parameters
    ax = apply_plot_params(params,ax)
    
    if params['overlay_average']:
        # Check on the dimensions of the data
        if len(ydata.shape)>1:
            ydata_mean = np.average(ydata,axis=1)
            ax.hold('on')
            ax.plot(xdata, ydata_mean, linewidth=2, color=params['overlay_average_color'])

        else:
            print('Ignoring ''overlay_average'', ydata is 1D')
    
    plt.tight_layout()              
    
    if params['save_fig']:
        # Save the figure to the specified location
        plt.savefig(params['output_fig_path'],transparent=True)

    # Turn plot interactivity back on in case it was turned off
    plt.ion()
    fig_handle = plt.gcf()
    line_handles = ax.get_lines()
    
    if params['autoclose']:
        # Close the figure containing the current axes
        plt.close(ax.figure)
        fig_handle = []
        line_handles = []
        ax = []
            

    return fig_handle, ax, line_handles