"""
from common_lib.plot_setting.save_plot_routines import CREATE_PDF_OBJECT,\
SAVE_FIGURE_IN_PDF_FILE


pdf_obj      = CREATE_PDF_OBJECT(pdf_filename)
fig,ax       = plt.subplots(1)
SAVE_FIGURE_IN_PDF_FILE(pdf_obj,fig,"y")

"""



import numpy as np
import matplotlib.pyplot as plt
import matplotlib.backends.backend_pdf

def USAGE_EXAMPLE():
    xdata        = np.linspace(-10.0,10.0,1001)
    ydata1       = np.exp(-xdata**2.0)
    ydata2       = np.exp(-(xdata-5.0)**2.0)
    ydata        = np.array([ydata1,ydata2]).T
    pdf_filename = "output.pdf"
    pdf_obj      = CREATE_PDF_OBJECT(pdf_filename)
    for indx in range(ydata.shape[1]):
        fig,ax       = plt.subplots(1)
        ax.plot(xdata,ydata[:,indx])
        if indx == ydata.shape[1] - 1:
            SAVE_FIGURE_IN_PDF_FILE(pdf_obj,fig,"y")
        else:
            SAVE_FIGURE_IN_PDF_FILE(pdf_obj,fig)

def CREATE_PDF_OBJECT(pdf_filename):
    pdf = matplotlib.backends.backend_pdf.PdfPages(pdf_filename)
    return pdf

def SAVE_FIGURE_IN_PDF_FILE(pdf,fig,flag_last_plot="n"):
    pdf.savefig(fig,dpi=200)
    if flag_last_plot == "y":
        pdf.close()



