Skip to content

Commit

Permalink
Backport PR matplotlib#27481: Fixing Pylab documentation in API inter…
Browse files Browse the repository at this point in the history
…face overview
  • Loading branch information
timhoffm authored and meeseeksmachine committed Dec 9, 2023
1 parent 11715f9 commit f9bcd6b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions galleries/users_explain/figure/api_interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ Appendix: "pylab" interface
---------------------------

There is one further interface that is highly discouraged, and that is to
basically do ``from matplotlib.pyplot import *``. This allows users to simply
call ``plot(x, y)``. While convenient, this can lead to obvious problems if the
user unwittingly names a variable the same name as a pyplot method.
basically do ``from matplotlib.pylab import *``. This 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 considered bad practice in modern python, 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.

0 comments on commit f9bcd6b

Please sign in to comment.