save_plot_to_pdf
- ssapy.plotUtils.save_plot_to_pdf(figure, pdf_path)[source][source]
- Save a Matplotlib figure to a PDF file, with support for merging with existing PDFs. - Parameters: - figure (matplotlib.figure.Figure): The Matplotlib figure to be saved. - pdf_path (str): The path to the PDF file. If the file exists, the figure will be appended to it. - Returns: None - This function saves a Matplotlib figure as a PNG in-memory and then converts it to a PDF. If the specified PDF file already exists, the new figure is appended to it. Otherwise, a new PDF file is created. The function also keeps track of how many times it has been called using a global variable save_plot_to_pdf_call_count. - The function performs the following steps: 1. Expands the user directory if the path starts with ~. 2. Generates a temporary PDF path by appending “_temp.pdf” to the original path. 3. Saves the figure as a PNG in-memory using a BytesIO buffer. 4. Opens the in-memory PNG using PIL and creates a new figure to display the image. 5. Saves the new figure with the image into a temporary PDF. 6. If the specified PDF file exists, merges the temporary PDF with the existing one. - Otherwise, renames the temporary PDF to the specified path. - Closes the original and temporary figures and prints a message indicating the save location. 
 - Example usage: ``` import matplotlib.pyplot as plt - fig, ax = plt.subplots() ax.plot([1, 2, 3], [4, 5, 6]) save_plot_to_pdf(fig, ‘~/Desktop/my_plot.pdf’) ```