|
1 | 1 | """
|
| 2 | +`pylab` is a historic interface and its use is strongly discouraged. The equivalent |
| 3 | +replacement is `matplotlib.pyplot`. See :ref:` api_interfaces` for a full overview |
| 4 | +of Matplotlib interfaces. |
| 5 | +
|
| 6 | +`pylab` was designed to support a MATLAB-like way of working with all plotting related |
| 7 | +functions directly available in the global namespace. This was achieved through a |
| 8 | +wildcard import (``from pylab import *``). |
| 9 | +
|
2 | 10 | .. warning::
|
3 |
| - Since heavily importing into the global namespace may result in unexpected |
4 |
| - behavior, the use of pylab is strongly discouraged. Use `matplotlib.pyplot` |
5 |
| - instead. |
6 |
| -
|
7 |
| -`pylab` is a module that includes `matplotlib.pyplot`, `numpy`, `numpy.fft`, |
8 |
| -`numpy.linalg`, `numpy.random`, and some additional functions, all within |
9 |
| -a single namespace. Its original purpose was to mimic a MATLAB-like way |
10 |
| -of working by importing all functions into the global namespace. This is |
11 |
| -considered bad style nowadays. |
| 11 | + The use of `pylab` is discouraged for the following reasons: |
| 12 | +
|
| 13 | + ``from pylab import *`` imports all the functions from `matplotlib.pyplot`, `numpy`, |
| 14 | + `numpy.fft`, `numpy.linalg`, and `numpy.random`, and some additional functions into |
| 15 | + the global namespace. |
| 16 | +
|
| 17 | + Such a pattern is nowadays considered bad practice, as it clutters the global |
| 18 | + namespace. Even more severely, in the case of `pylab`, this will overwrite some |
| 19 | + builtin functions (e.g. the builtin `sum` will be replaced by `numpy.sum`), which |
| 20 | + can lead to unexpected behavior. |
| 21 | +
|
12 | 22 | """
|
13 | 23 |
|
14 | 24 | from matplotlib.cbook import flatten, silent_list
|
|
0 commit comments