Two points:

  1. change backend of matplotlib: 

import matplotlib.pyplot as plt
plt.switch_backend('agg')

  2. save figure via PdfPages:

from matplot.backends.backend_pdf import PdfPages
pdf = PdfPages('cut_figure.pdf')         #先创建一个pdf文件
plt.figure()
...
...
pdf.savefig()                            #将图片保存在pdf文件中
plt.close()
pdf.close()                              #这句必须有,否则程序结束pdf文件无法打开

 

相关文章:

  • 2022-12-23
  • 2021-07-30
  • 2021-09-15
  • 2021-08-11
  • 2021-06-27
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2021-08-05
  • 2021-11-15
  • 2021-11-03
  • 2022-12-23
相关资源
相似解决方案