服务器使用matplotlib绘图

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文件无法打开

 

posted @ 2020-03-20 19:55  leizhao  阅读(738)  评论(0编辑  收藏  举报