服务器使用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文件无法打开

 

上一篇:记录bug:dao自动注入失败


下一篇:Spring Cloud源码实践-工程搭建