Many users report initial problems trying to use maptlotlib in web application servers, because by default Matplotlib ships configured to work with a graphical user interface which may require an X11 connection. Since many barebones application servers do not have X11 enabled, you may get errors if you don't configure Matplotlib for use in these environments. Most importantly, you need to decide what kinds of images you want to generate (PNG, PDF, SVG) and configure the appropriate default backend. For 99% of users, this will be the Agg backend, which uses the C++ antigrain rendering engine to make nice PNGs. The Agg backend is also configured to recognize requests to generate other output formats (PDF, PS, EPS, SVG). The easiest way to configure Matplotlib to use Agg is to call:
# do this before importing pylab or pyplot
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
配置Matplotlib在Web服务器

本文解决许多用户在尝试将Matplotlib集成到Web应用服务器时遇到的问题,由于默认配置适用于带有图形用户界面的环境,这可能导致没有启用X11连接的应用服务器出现错误。文章详细介绍了如何通过设置默认后端为Agg来避免这些问题,该后端使用C++抗锯齿渲染引擎生成高质量的PNG图像,并能识别其他输出格式请求。

418

被折叠的 条评论
为什么被折叠?



