Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -60,19 +60,17 @@ async def run_code(code: Code):
|
|
60 |
# plt.savefig(file_path)
|
61 |
# plt.close()
|
62 |
|
63 |
-
# Get all open
|
64 |
figures = [plt.figure(i) for i in plt.get_fignums()]
|
65 |
-
|
66 |
|
67 |
-
# Save all figures in a single PDF
|
68 |
-
|
69 |
-
|
70 |
-
for fig in figures
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
print("No open figures found.")
|
76 |
|
77 |
|
78 |
# return Response(content=img_buffer.getvalue(), media_type="image/png")
|
|
|
60 |
# plt.savefig(file_path)
|
61 |
# plt.close()
|
62 |
|
63 |
+
# Get all open figures
|
64 |
figures = [plt.figure(i) for i in plt.get_fignums()]
|
|
|
65 |
|
66 |
+
# Save all figures in a single PDF using PdfPages
|
67 |
+
pdf_filename = "all_graphs.pdf"
|
68 |
+
with PdfPages(pdf_filename) as pdf:
|
69 |
+
for fig in figures:
|
70 |
+
pdf.savefig(fig) # Save each figure as a page in the PDF
|
71 |
+
plt.close(fig) # Close the figure to free memory
|
72 |
+
|
73 |
+
print(f"Saved all figures to {pdf_filename}")
|
|
|
74 |
|
75 |
|
76 |
# return Response(content=img_buffer.getvalue(), media_type="image/png")
|