diff --git a/examples/pylab_examples/shared_axis_across_figures.py b/examples/pylab_examples/shared_axis_across_figures.py index b4cc8c70d35c..8cbfb9df680d 100644 --- a/examples/pylab_examples/shared_axis_across_figures.py +++ b/examples/pylab_examples/shared_axis_across_figures.py @@ -3,18 +3,17 @@ another. This is not the right way to do this for two axes in the same figure -- use the sharex and sharey property in that case """ -# -*- noplot -*- -import numpy -from pylab import figure, show +import numpy as np +import matplotlib.pyplot as plt -fig1 = figure() -fig2 = figure() +fig1 = plt.figure() +fig2 = plt.figure() ax1 = fig1.add_subplot(111) ax2 = fig2.add_subplot(111, sharex=ax1, sharey=ax1) -ax1.plot(numpy.random.rand(100), 'o') -ax2.plot(numpy.random.rand(100), 'o') +ax1.plot(np.random.rand(100), 'o') +ax2.plot(np.random.rand(100), 'o') # In the latest release, it is no longer necessary to do anything # special to share axes across figures: @@ -25,4 +24,4 @@ # ax1.sharey_foreign(ax2) # ax2.sharey_foreign(ax1) -show() +plt.show() diff --git a/examples/pylab_examples/shared_axis_demo.py b/examples/pylab_examples/shared_axis_demo.py index e80478ea5d3f..e92b323e0312 100644 --- a/examples/pylab_examples/shared_axis_demo.py +++ b/examples/pylab_examples/shared_axis_demo.py @@ -27,26 +27,27 @@ setp( ax2.get_xticklabels(), visible=False) - """ -from pylab import * +import matplotlib.pyplot as plt +import numpy as np + +t = np.arange(0.01, 5.0, 0.01) +s1 = np.sin(2*np.pi*t) +s2 = np.exp(-t) +s3 = np.sin(4*np.pi*t) -t = arange(0.01, 5.0, 0.01) -s1 = sin(2*pi*t) -s2 = exp(-t) -s3 = sin(4*pi*t) -ax1 = subplot(311) -plot(t, s1) -setp(ax1.get_xticklabels(), fontsize=6) +ax1 = plt.subplot(311) +plt.plot(t, s1) +plt.setp(ax1.get_xticklabels(), fontsize=6) # share x only -ax2 = subplot(312, sharex=ax1) -plot(t, s2) +ax2 = plt.subplot(312, sharex=ax1) +plt.plot(t, s2) # make these tick labels invisible -setp(ax2.get_xticklabels(), visible=False) +plt.setp(ax2.get_xticklabels(), visible=False) # share x and y -ax3 = subplot(313, sharex=ax1, sharey=ax1) -plot(t, s3) -xlim(0.01, 5.0) -show() +ax3 = plt.subplot(313, sharex=ax1, sharey=ax1) +plt.plot(t, s3) +plt.xlim(0.01, 5.0) +plt.show() diff --git a/examples/pylab_examples/simple_plot.py b/examples/pylab_examples/simple_plot.py index 157e6e4851aa..8afbbea53f46 100644 --- a/examples/pylab_examples/simple_plot.py +++ b/examples/pylab_examples/simple_plot.py @@ -1,12 +1,13 @@ -from pylab import * +import matplotlib.pyplot as plt +import numpy as np -t = arange(0.0, 2.0, 0.01) -s = sin(2*pi*t) -plot(t, s) +t = np.arange(0.0, 2.0, 0.01) +s = np.sin(2*np.pi*t) +plt.plot(t, s) -xlabel('time (s)') -ylabel('voltage (mV)') -title('About as simple as it gets, folks') -grid(True) -savefig("test.png") -show() +plt.xlabel('time (s)') +plt.ylabel('voltage (mV)') +plt.title('About as simple as it gets, folks') +plt.grid(True) +plt.savefig("test.png") +plt.show() diff --git a/examples/pylab_examples/simple_plot_fps.py b/examples/pylab_examples/simple_plot_fps.py index 6ecfd8c53d4a..23970470d313 100755 --- a/examples/pylab_examples/simple_plot_fps.py +++ b/examples/pylab_examples/simple_plot_fps.py @@ -1,32 +1,30 @@ -#!/usr/bin/env python - """ Example: simple line plot. Show how to make and save a simple line plot with labels, title and grid """ -# -*- noplot -*- -from __future__ import print_function -from pylab import * +from __future__ import print_function # not necessary in Python 3.x +import matplotlib.pyplot as plt +import numpy as np +import time -ion() -t = arange(0.0, 1.0 + 0.001, 0.001) -s = cos(2*2*pi*t) -plot(t, s, '-', lw=2) +plt.ion() -xlabel('time (s)') -ylabel('voltage (mV)') -title('About as simple as it gets, folks') -grid(True) +t = np.arange(0.0, 1.0 + 0.001, 0.001) +s = np.cos(2*2*np.pi*t) +plt.plot(t, s, '-', lw=2) -import time +plt.xlabel('time (s)') +plt.ylabel('voltage (mV)') +plt.title('About as simple as it gets, folks') +plt.grid(True) frames = 100.0 t = time.time() c = time.clock() for i in range(int(frames)): part = i / frames - axis([0.0, 1.0 - part, -1.0 + part, 1.0 - part]) + plt.axis([0.0, 1.0 - part, -1.0 + part, 1.0 - part]) wallclock = time.time() - t user = time.clock() - c print("wallclock:", wallclock) diff --git a/examples/pylab_examples/specgram_demo.py b/examples/pylab_examples/specgram_demo.py index edfc4c38fbaf..a5373c58fc41 100644 --- a/examples/pylab_examples/specgram_demo.py +++ b/examples/pylab_examples/specgram_demo.py @@ -1,17 +1,17 @@ -#!/usr/bin/env python -from pylab import * +import matplotlib.pyplot as plt +import numpy as np dt = 0.0005 -t = arange(0.0, 20.0, dt) -s1 = sin(2*pi*100*t) -s2 = 2*sin(2*pi*400*t) +t = np.arange(0.0, 20.0, dt) +s1 = np.sin(2*np.pi*100*t) +s2 = 2*np.sin(2*np.pi*400*t) # create a transient "chirp" -mask = where(logical_and(t > 10, t < 12), 1.0, 0.0) +mask = np.where(np.logical_and(t > 10, t < 12), 1.0, 0.0) s2 = s2 * mask # add some noise into the mix -nse = 0.01*randn(len(t)) +nse = 0.01*np.random.random(size=len(t)) x = s1 + s2 + nse # the signal NFFT = 1024 # the length of the windowing segments @@ -22,9 +22,9 @@ # the power is computed, and im is the matplotlib.image.AxesImage # instance -ax1 = subplot(211) -plot(t, x) -subplot(212, sharex=ax1) -Pxx, freqs, bins, im = specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900, - cmap=cm.gist_heat) -show() +ax1 = plt.subplot(211) +plt.plot(t, x) +plt.subplot(212, sharex=ax1) +Pxx, freqs, bins, im = plt.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900, + cmap=plt.cm.gist_heat) +plt.show() diff --git a/examples/pylab_examples/spectrum_demo.py b/examples/pylab_examples/spectrum_demo.py index 8278e1900e96..a6b6a51de93a 100644 --- a/examples/pylab_examples/spectrum_demo.py +++ b/examples/pylab_examples/spectrum_demo.py @@ -1,31 +1,29 @@ -#!/usr/bin/env python -# python - -from pylab import * +import matplotlib.pyplot as plt +import numpy as np dt = 0.01 Fs = 1/dt -t = arange(0, 10, dt) -nse = randn(len(t)) -r = exp(-t/0.05) +t = np.arange(0, 10, dt) +nse = np.random.randn(len(t)) +r = np.exp(-t/0.05) -cnse = convolve(nse, r)*dt +cnse = np.convolve(nse, r)*dt cnse = cnse[:len(t)] -s = 0.1*sin(2*pi*t) + cnse +s = 0.1*np.sin(2*np.pi*t) + cnse -subplot(3, 2, 1) -plot(t, s) +plt.subplot(3, 2, 1) +plt.plot(t, s) -subplot(3, 2, 3) -magnitude_spectrum(s, Fs=Fs) +plt.subplot(3, 2, 3) +plt.magnitude_spectrum(s, Fs=Fs) -subplot(3, 2, 4) -magnitude_spectrum(s, Fs=Fs, scale='dB') +plt.subplot(3, 2, 4) +plt.magnitude_spectrum(s, Fs=Fs, scale='dB') -subplot(3, 2, 5) -angle_spectrum(s, Fs=Fs) +plt.subplot(3, 2, 5) +plt.angle_spectrum(s, Fs=Fs) -subplot(3, 2, 6) -phase_spectrum(s, Fs=Fs) +plt.subplot(3, 2, 6) +plt.phase_spectrum(s, Fs=Fs) -show() +plt.show() diff --git a/examples/pylab_examples/subplots_adjust.py b/examples/pylab_examples/subplots_adjust.py index c78371680b13..e04afca3431e 100644 --- a/examples/pylab_examples/subplots_adjust.py +++ b/examples/pylab_examples/subplots_adjust.py @@ -1,12 +1,12 @@ -from pylab import * +import matplotlib.pyplot as plt +import numpy as np +plt.subplot(211) +plt.imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r) +plt.subplot(212) +plt.imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r) -subplot(211) -imshow(rand(100, 100), cmap=cm.BuPu_r) -subplot(212) -imshow(rand(100, 100), cmap=cm.BuPu_r) - -subplots_adjust(bottom=0.1, right=0.8, top=0.9) -cax = axes([0.85, 0.1, 0.075, 0.8]) -colorbar(cax=cax) -show() +plt.subplots_adjust(bottom=0.1, right=0.8, top=0.9) +cax = plt.axes([0.85, 0.1, 0.075, 0.8]) +plt.colorbar(cax=cax) +plt.show()