Skip to content

Move pylab documentation to its own module page #26396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ Further reading:

.. _api-index:

The pylab API (discouraged)
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: pylab
:no-members:

Modules
-------

Expand Down Expand Up @@ -162,3 +156,4 @@ Alphabetical list of modules:
toolkits/mplot3d.rst
toolkits/axes_grid1.rst
toolkits/axisartist.rst
pylab.rst
6 changes: 6 additions & 0 deletions doc/api/pylab.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*********
``pylab``
*********

.. automodule:: pylab
:no-members:
28 changes: 19 additions & 9 deletions lib/matplotlib/pylab.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
"""
`pylab` is a historic interface and its use is strongly discouraged. The equivalent
replacement is `matplotlib.pyplot`. See :ref:` api_interfaces` for a full overview
of Matplotlib interfaces.

`pylab` was designed to support a MATLAB-like way of working with all plotting related
functions directly available in the global namespace. This was achieved through a
wildcard import (``from pylab import *``).

.. warning::
Since heavily importing into the global namespace may result in unexpected
behavior, the use of pylab is strongly discouraged. Use `matplotlib.pyplot`
instead.

`pylab` is a module that includes `matplotlib.pyplot`, `numpy`, `numpy.fft`,
`numpy.linalg`, `numpy.random`, and some additional functions, all within
a single namespace. Its original purpose was to mimic a MATLAB-like way
of working by importing all functions into the global namespace. This is
considered bad style nowadays.
The use of `pylab` is discouraged for the following reasons:

``from pylab import *`` imports all the functions from `matplotlib.pyplot`, `numpy`,
`numpy.fft`, `numpy.linalg`, and `numpy.random`, and some additional functions into
the global namespace.

Such a pattern is nowadays considered bad practice, as it clutters the global
namespace. Even more severely, in the case of `pylab`, this will overwrite some
builtin functions (e.g. the builtin `sum` will be replaced by `numpy.sum`), which
can lead to unexpected behavior.

"""

from matplotlib.cbook import flatten, silent_list
Expand Down