Save figures.
    
    Parameters
    ----------
    filename - str
        Name of output file
        
    fig_IDs - int, numpy.array, list, optional, default None
        A list of open figure IDs or a figure ID that will be saved to a
        pdf/png file respectively.
    
    **kwargs - 
        Extra keyword arguments passed into 'matplotlib.pyplot.savefig'.

def save_figures(filename, fig_IDs=None, **kwargs):
    """
    Save figures.
    
    Parameters
    ----------
    filename - str
        Name of output file
        
    fig_IDs - int, numpy.array, list, optional, default None
        A list of open figure IDs or a figure ID that will be saved to a
        pdf/png file respectively.
    
    **kwargs - 
        Extra keyword arguments passed into 'matplotlib.pyplot.savefig'.
        
    """
    import matplotlib.pyplot as plt
    if(fig_IDs is not None):
        if(type(fig_IDs) is list):
            savetype = 'pdf'
        else:
            savetype = 'png'
    else:
        savetype = 'pdf'

    if(savetype == 'pdf'):
        from matplotlib.backends.backend_pdf import PdfPages

        if(len(filename.split('.')) == 1):
            filename = filename + '.pdf'
        else:
            filename = '.'.join(filename.split('.')[:-1])+'.pdf'

        pdf = PdfPages(filename)

        if fig_IDs is None:
            figs = [plt.figure(n) for n in plt.get_fignums()]
        else:
            figs = [plt.figure(n) for n in fig_IDs]

        for fig in figs:
            fig.savefig(pdf, format='pdf', **kwargs)
        pdf.close()
    elif(savetype == 'png'):
        plt.figure(fig_IDs).savefig(filename, **kwargs)