Writing matplotlib figure to a buffer, then reading as a file for embedding an image in a PDF
问题 I'm trying to save several matplotlib figures into specific locations in a PDF being created with FPDF. I'd prefer not to have to dump these figures to files and then pull them back in. The better solution seems to be writing them to a buffer, then reading them back in, but I'm not sure that's possible. Simplified code: import pandas as pd import matplotlib.pyplot as plt from fpdf import FPDF from io import BytesIO import base64 # create figure fig = plt.figure() # add plot ax = pd.Series( [1