解决方法:
参见:http://matplotlib.sourceforge.net/faq/howto_faq.html#howto-webapp的Matplotlib in a web application server节
http://matplotlib.sourceforge.net/faq/usage_faq.html#what-is-a-backend讲述了backend是什么。
There are two types of backends: user interface backends (for use in pygtk, wxpython, tkinter, qt, macosx, or fltk; also referred to as “interactive backends”) and hardcopy backends to make image files (PNG, SVG, PDF, PS; also referred to as “non-interactive backends”)
所以只要选择一些non-interactive backend 就可以在无前端显示的情况下,执行脚本画图表并写入image文件中。
在python文件的起始处添加
import matplotlib
matplotlib.use('Agg')