0

I am trying to save scatter plots from a list of dataframes in one pdf file using this:

pdf = matplotlib.backends.backend_pdf.PdfPages("./output.pdf")
for df in list_degs_dfs:
    dfplt = df.plot.scatter("DEratio", "MI_scaled")
    pdf.savefig(dfplt)
pdf.close()

But I get this error:

ValueError: No figure AxesSubplot(0.125,0.11;0.775x0.77)

I thought it can be an issue with converting the plots to matplotlib figure and tried this:

import matplotlib.pyplot as plt
pdf = matplotlib.backends.backend_pdf.PdfPages("./output.pdf")
for df in list_degs_dfs:
    dfplt = df.plot.scatter("DEratio", "MI_scaled")
    dfplt = plt.figure(dfplt)
    pdf.savefig(dfplt.Figure)
pdf.close()

and got this:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'AxesSubplot'

How to save all dfplt figrues from all df dataframes from a list of dataframes in one file?

1 Answer 1

2

savefig should not take any arguments, it will save the currently active figure handle.

pdf = matplotlib.backends.backend_pdf.PdfPages("./output.pdf")
for df in list_degs_dfs:
    dfplt = df.plot.scatter("DEratio", "MI_scaled")
    pdf.savefig() # saves the active handle
pdf.close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.