Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72578a7

Browse files
authored
Merge pull request #26396 from timhoffm/pylab
Move pylab documentation to its own module page
2 parents 395f85a + 52a5ae4 commit 72578a7

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

doc/api/index.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ Further reading:
8080

8181
.. _api-index:
8282

83-
The pylab API (discouraged)
84-
^^^^^^^^^^^^^^^^^^^^^^^^^^^
85-
86-
.. automodule:: pylab
87-
:no-members:
88-
8983
Modules
9084
-------
9185

@@ -162,3 +156,4 @@ Alphabetical list of modules:
162156
toolkits/mplot3d.rst
163157
toolkits/axes_grid1.rst
164158
toolkits/axisartist.rst
159+
pylab.rst

doc/api/pylab.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*********
2+
``pylab``
3+
*********
4+
5+
.. automodule:: pylab
6+
:no-members:

lib/matplotlib/pylab.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
"""
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+
210
.. 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+
1222
"""
1323

1424
from matplotlib.cbook import flatten, silent_list

0 commit comments

Comments
 (0)