pylab.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. `pylab` was designed to support a MATLAB-like way of working with all plotting related
  6. functions directly available in the global namespace. This was achieved through a
  7. wildcard import (``from pylab import *``).
  8. .. warning::
  9. The use of `pylab` is discouraged for the following reasons:
  10. ``from pylab import *`` imports all the functions from `matplotlib.pyplot`, `numpy`,
  11. `numpy.fft`, `numpy.linalg`, and `numpy.random`, and some additional functions into
  12. the global namespace.
  13. Such a pattern is considered bad practice in modern python, as it clutters the global
  14. namespace. Even more severely, in the case of `pylab`, this will overwrite some
  15. builtin functions (e.g. the builtin `sum` will be replaced by `numpy.sum`), which
  16. can lead to unexpected behavior.
  17. """
  18. from matplotlib.cbook import flatten, silent_list
  19. import matplotlib as mpl
  20. from matplotlib.dates import (
  21. date2num, num2date, datestr2num, drange, DateFormatter, DateLocator,
  22. RRuleLocator, YearLocator, MonthLocator, WeekdayLocator, DayLocator,
  23. HourLocator, MinuteLocator, SecondLocator, rrule, MO, TU, WE, TH, FR,
  24. SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY,
  25. relativedelta)
  26. # bring all the symbols in so folks can import them from
  27. # pylab in one fell swoop
  28. ## We are still importing too many things from mlab; more cleanup is needed.
  29. from matplotlib.mlab import (
  30. detrend, detrend_linear, detrend_mean, detrend_none, window_hanning,
  31. window_none)
  32. from matplotlib import cbook, mlab, pyplot as plt
  33. from matplotlib.pyplot import *
  34. from numpy import *
  35. from numpy.fft import *
  36. from numpy.random import *
  37. from numpy.linalg import *
  38. import numpy as np
  39. import numpy.ma as ma
  40. # don't let numpy's datetime hide stdlib
  41. import datetime
  42. # This is needed, or bytes will be numpy.random.bytes from
  43. # "from numpy.random import *" above
  44. bytes = __import__("builtins").bytes
  45. # We also don't want the numpy version of these functions
  46. abs = __import__("builtins").abs
  47. max = __import__("builtins").max
  48. min = __import__("builtins").min
  49. round = __import__("builtins").round