|
1 | | -matplotlib API |
| 1 | +.. _api_examples: |
| 2 | + |
| 3 | +Matplotlib API |
2 | 4 | ============== |
3 | 5 |
|
4 | | -These examples use the matplotlib api rather than the pylab/pyplot |
| 6 | +These examples use the Matplotlib api rather than the pylab/pyplot |
5 | 7 | procedural state machine. For robust, production level scripts, or |
6 | 8 | for applications or web application servers, we recommend you use the |
7 | | -matplotlib API directly as it gives you the maximum control over your |
| 9 | +Matplotlib API directly as it gives you the maximum control over your |
8 | 10 | figures, axes and plottng commands. |
9 | 11 |
|
10 | 12 | The example agg_oo.py is the simplest example of using the Agg backend |
11 | 13 | which is readily ported to other output formats. This example is a |
12 | 14 | good starting point if your are a web application developer. Many of |
13 | | -the other examples in this directory use matplotlib.pyplot just to |
| 15 | +the other examples in this directory use ``matplotlib.pyplot`` just to |
14 | 16 | create the figure and show calls, and use the API for everything else. |
15 | 17 | This is a good solution for production quality scripts. For full |
16 | 18 | fledged GUI applications, see the user_interfaces examples. |
17 | | - |
18 | | -Example style guide |
19 | | -=================== |
20 | | - |
21 | | -If you are creating new examples, you cannot import pylab or import * |
22 | | -from any module in your examples. The only three functions allowed |
23 | | -from pyplot are "figure", "show" and "close", which you can use as |
24 | | -convenience functions for managing figures. All other matplotlib |
25 | | -functionality must illustrate the API. |
26 | | - |
27 | | -A simple example of the recommended style is:: |
28 | | - |
29 | | - import numpy as np |
30 | | - import matplotlib.pyplot as plt |
31 | | - |
32 | | - fig, ax = plt.subplots() |
33 | | - ax.plot(np.random.rand(10)) |
34 | | - ax.set_xlabel('some x data') |
35 | | - ax.set_ylabel('some y data') |
36 | | - ax.set_title('some title') |
37 | | - ax.grid(True) |
38 | | - fig.savefig('myfig') |
39 | | - plt.show() |
0 commit comments