|
| 1 | +***** |
| 2 | +HOWTO |
| 3 | +***** |
| 4 | + |
| 5 | +How do I use matplotlib in a web application server? |
| 6 | +==================================================== |
| 7 | + |
| 8 | +Many users report initial problems trying to use maptlotlib in web |
| 9 | +application servers, because by default matplotlib ships configured to |
| 10 | +work with a graphical user interface which may require an X11 |
| 11 | +connection. Since many barebones application servers do not have X11 |
| 12 | +enabled, you may get errors if you don't configure matplotlib for use |
| 13 | +in these environments. Most importantly, you need to decide what |
| 14 | +kinds of images you want to generate (PNG, PDF, SVG) and configure the |
| 15 | +appropriate default backend. For 99% of users, this will be the Agg |
| 16 | +backend, which uses the C++ `antigrain <http://antigrain.com`_ |
| 17 | +rendering engine to make nice PNGs. The Agg backend is also |
| 18 | +configured to recognize requests to generate other output formats |
| 19 | +(PDF, PS, EPS, SVG). The easiest way to configure matplotlib to use |
| 20 | +Agg is to call:: |
| 21 | + |
| 22 | + # do this before importing pylab or pyplot |
| 23 | + import matplotlib |
| 24 | + matplotlib.use('Agg') |
| 25 | + import matplotlib.pyplot as plt |
| 26 | + |
| 27 | +Alternatively, you can avoid pylab/pyplot altogeher, which will give |
| 28 | +you a little more control, by calling the API directly as shown in |
| 29 | +`agg_oo.py <http://matplotlib.sf.net/examples/api/agg_oo.py`_ . |
| 30 | + |
| 31 | +You can either generate hardcopy on the filesystem by calling savefig:: |
| 32 | + |
| 33 | + # do this before importing pylab or pyplot |
| 34 | + import matplotlib |
| 35 | + matplotlib.use('Agg') |
| 36 | + import matplotlib.pyplot as plt |
| 37 | + fig = plt.figure() |
| 38 | + ax = fig.add_subplot(111) |
| 39 | + ax.plot([1,2,3]) |
| 40 | + fig.savefig('test.png') |
| 41 | + |
| 42 | +or by saving to a file handle:: |
| 43 | + |
| 44 | + import sys |
| 45 | + fig.savefig(sys.stdout) |
| 46 | + |
| 47 | + |
| 48 | +How do I use matplotlib with apache? |
| 49 | +------------------------------------ |
| 50 | + |
| 51 | +TODO |
| 52 | + |
| 53 | +How do I use matplotlib with dhango? |
| 54 | +------------------------------------ |
| 55 | + |
| 56 | +TODO |
| 57 | + |
| 58 | +How do I use matplotlib with zope? |
| 59 | +---------------------------------- |
| 60 | + |
| 61 | +TODO |
0 commit comments