From c971b92be8daf1d2582c3803215095bf5adb0c70 Mon Sep 17 00:00:00 2001 From: y1thof Date: Fri, 22 Jun 2018 09:26:56 +0200 Subject: [PATCH] remove more pylab references --- lib/matplotlib/backends/backend_template.py | 2 +- lib/matplotlib/mlab.py | 14 +++-- lib/matplotlib/widgets.py | 64 ++++++++++----------- tutorials/intermediate/artists.py | 8 +-- tutorials/introductory/usage.py | 3 +- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/lib/matplotlib/backends/backend_template.py b/lib/matplotlib/backends/backend_template.py index 65a782a66089..1702c9fe85bb 100644 --- a/lib/matplotlib/backends/backend_template.py +++ b/lib/matplotlib/backends/backend_template.py @@ -23,7 +23,7 @@ matplotlib.use('xxx') import matplotlib.pyplot as plt plt.plot([1,2,3]) - show() + plt.show() matplotlib also supports external backends, so you can place you can use any module in your PYTHONPATH with the syntax:: diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index f857cc79fcc5..1cc3b434d2ee 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -4000,13 +4000,15 @@ def offset_line(y, yerr): * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: - from pylab import * - x = linspace(0, 2*pi, num=100, endpoint=True) - y = sin(x) + import numpy as np + import matplotlib.pyplot as plt + + x = np.linspace(0, 2*np.pi, num=100, endpoint=True) + y = np.sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) - plot(x, y) - fill_between(x, ym, y2=yp) - show() + plt.plot(x, y) + plt.fill_between(x, y_minus, y2=y_plus) + plt.show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index d78ee8f5e080..bd9c58c50625 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1342,7 +1342,7 @@ class MultiCursor(Widget): multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1, horizOn=False, vertOn=True) - show() + plt.show() """ def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True, @@ -1954,33 +1954,33 @@ class RectangleSelector(_SelectorWidget): Example usage:: - from matplotlib.widgets import RectangleSelector - from pylab import * + import numpy as np + import matplotlib.pyplot as plt + from matplotlib.widgets import RectangleSelector def onselect(eclick, erelease): - 'eclick and erelease are matplotlib events at press and release' - print(' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)) - print(' endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)) - print(' used button : ', eclick.button) + "eclick and erelease are matplotlib events at press and release." + print('startposition: (%f, %f)' % (eclick.xdata, eclick.ydata)) + print('endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)) + print('used button : ', eclick.button) def toggle_selector(event): - print(' Key pressed.') + print('Key pressed.') if event.key in ['Q', 'q'] and toggle_selector.RS.active: - print(' RectangleSelector deactivated.') + print('RectangleSelector deactivated.') toggle_selector.RS.set_active(False) if event.key in ['A', 'a'] and not toggle_selector.RS.active: - print(' RectangleSelector activated.') + print('RectangleSelector activated.') toggle_selector.RS.set_active(True) - x = arange(100)/(99.0) - y = sin(x) - fig = figure - ax = subplot(111) - ax.plot(x,y) + x = np.arange(100.) / 99 + y = np.sin(x) + fig, ax = plt.subplots() + ax.plot(x, y) toggle_selector.RS = RectangleSelector(ax, onselect, drawtype='line') - connect('key_press_event', toggle_selector) - show() + fig.canvas.connect('key_press_event', toggle_selector) + plt.show() """ _shape_klass = Rectangle @@ -2385,33 +2385,33 @@ class EllipseSelector(RectangleSelector): Example usage:: - from matplotlib.widgets import EllipseSelector - from pylab import * + import numpy as np + import matplotlib.pyplot as plt + from matplotlib.widgets import EllipseSelector def onselect(eclick, erelease): - 'eclick and erelease are matplotlib events at press and release' - print(' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)) - print(' endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)) - print(' used button : ', eclick.button) + "eclick and erelease are matplotlib events at press and release." + print('startposition: (%f, %f)' % (eclick.xdata, eclick.ydata)) + print('endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)) + print('used button : ', eclick.button) def toggle_selector(event): print(' Key pressed.') if event.key in ['Q', 'q'] and toggle_selector.ES.active: - print(' EllipseSelector deactivated.') + print('EllipseSelector deactivated.') toggle_selector.RS.set_active(False) if event.key in ['A', 'a'] and not toggle_selector.ES.active: - print(' EllipseSelector activated.') + print('EllipseSelector activated.') toggle_selector.ES.set_active(True) - x = arange(100)/(99.0) - y = sin(x) - fig = figure - ax = subplot(111) - ax.plot(x,y) + x = np.arange(100.) / 99 + y = np.sin(x) + fig, ax = plt.subplots() + ax.plot(x, y) toggle_selector.ES = EllipseSelector(ax, onselect, drawtype='line') - connect('key_press_event', toggle_selector) - show() + fig.canvas.connect('key_press_event', toggle_selector) + plt.show() """ _shape_klass = Ellipse diff --git a/tutorials/intermediate/artists.py b/tutorials/intermediate/artists.py index aa5e04418edb..3ee20a910d73 100644 --- a/tutorials/intermediate/artists.py +++ b/tutorials/intermediate/artists.py @@ -218,7 +218,7 @@ class in the matplotlib API, and the one you will be working with most # If you are working interactively at the python shell, a handy way to # inspect the ``Artist`` properties is to use the # :func:`matplotlib.artist.getp` function (simply -# :func:`~matplotlib.pylab.getp` in pylab), which lists the properties +# :func:`~matplotlib.pyplot.getp` in pyplot), which lists the properties # and their values. This works for classes derived from ``Artist`` as # well, e.g., ``Figure`` and ``Rectangle``. Here are the ``Figure`` rectangle # properties mentioned above: @@ -556,9 +556,9 @@ class in the matplotlib API, and the one you will be working with most # the ticks are placed and how they are represented as strings. # # Each ``Axis`` object contains a :attr:`~matplotlib.axis.Axis.label` attribute -# (this is what :mod:`~matplotlib.pylab` modifies in calls to -# :func:`~matplotlib.pylab.xlabel` and :func:`~matplotlib.pylab.ylabel`) as well -# as a list of major and minor ticks. The ticks are +# (this is what :mod:`~matplotlib.pyplot` modifies in calls to +# :func:`~matplotlib.pyplot.xlabel` and :func:`~matplotlib.pyplot.ylabel`) as +# well as a list of major and minor ticks. The ticks are # :class:`~matplotlib.axis.XTick` and :class:`~matplotlib.axis.YTick` instances, # which contain the actual line and text primitives that render the ticks and # ticklabels. Because the ticks are dynamically created as needed (e.g., when diff --git a/tutorials/introductory/usage.py b/tutorials/introductory/usage.py index c1f9a9f0ce7a..43e803855b95 100644 --- a/tutorials/introductory/usage.py +++ b/tutorials/introductory/usage.py @@ -184,7 +184,8 @@ # :mod:`pylab` is a convenience module that bulk imports # :mod:`matplotlib.pyplot` (for plotting) and :mod:`numpy` # (for mathematics and working with arrays) in a single name space. -# Although many examples use :mod:`pylab`, it is no longer recommended. +# pylab is deprecated and its use is strongly discouraged because +# of namespace pollution. Use pyplot instead. # # For non-interactive plotting it is suggested # to use pyplot to create the figures and then the OO interface for