Matplotlib: 多张图像存放到一个 PDF 中

2025-04-06  本文已影响0人  LET149

https://matplotlib.org/stable/api/backend_pdf_api.html#module-matplotlib.backends.backend_pdf

matplotlib.backends.backend_pdf()

import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

pdf_used = PdfPages("/data/Zhiyong/AAA__Work/Analysis/PM-FCA/Figure-2/E___Resolution-selection_and_Marker-validation/marker_validation/output.pdf")     '# create the object to stote all plot

sc.pl.tsne(scanpy_oject_used, color='res_3_celltype', size=7, show=False)     # plot the first figure
fig_used=plt.gcf()     # capture the new plot
fig_used.set_size_inches(5,5)     # change the size of the current plot
pdf_used.savefig(fig_used)     # save the current plot to the pdf_used
plt.close()     # close the current plot

sc.pl.tsne(scanpy_oject_used, color='res_3_celltype', size=1, show=False)     # plot the second figure
fig_used=plt.gcf()
fig_used.set_size_inches(7,5)
pdf_used.savefig(fig_used)
plt.close()

pdf.close()     # close and output the pdf file
上一篇 下一篇

猜你喜欢

热点阅读