Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29b5d1d

Browse files
committed
Merge pull request #4659 from ericmjl/mep12-shared-to-spectrum
Mep12 shared to spectrum
2 parents 4c1404a + 7cb1ae3 commit 29b5d1d

File tree

6 files changed

+79
-82
lines changed

6 files changed

+79
-82
lines changed

examples/pylab_examples/shared_axis_across_figures.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
another. This is not the right way to do this for two axes in the
44
same figure -- use the sharex and sharey property in that case
55
"""
6-
# -*- noplot -*-
7-
import numpy
8-
from pylab import figure, show
6+
import numpy as np
7+
import matplotlib.pyplot as plt
98

10-
fig1 = figure()
11-
fig2 = figure()
9+
fig1 = plt.figure()
10+
fig2 = plt.figure()
1211

1312
ax1 = fig1.add_subplot(111)
1413
ax2 = fig2.add_subplot(111, sharex=ax1, sharey=ax1)
1514

16-
ax1.plot(numpy.random.rand(100), 'o')
17-
ax2.plot(numpy.random.rand(100), 'o')
15+
ax1.plot(np.random.rand(100), 'o')
16+
ax2.plot(np.random.rand(100), 'o')
1817

1918
# In the latest release, it is no longer necessary to do anything
2019
# special to share axes across figures:
@@ -25,4 +24,4 @@
2524
# ax1.sharey_foreign(ax2)
2625
# ax2.sharey_foreign(ax1)
2726

28-
show()
27+
plt.show()

examples/pylab_examples/shared_axis_demo.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,27 @@
2727
2828
setp( ax2.get_xticklabels(), visible=False)
2929
30-
3130
"""
32-
from pylab import *
31+
import matplotlib.pyplot as plt
32+
import numpy as np
33+
34+
t = np.arange(0.01, 5.0, 0.01)
35+
s1 = np.sin(2*np.pi*t)
36+
s2 = np.exp(-t)
37+
s3 = np.sin(4*np.pi*t)
3338

34-
t = arange(0.01, 5.0, 0.01)
35-
s1 = sin(2*pi*t)
36-
s2 = exp(-t)
37-
s3 = sin(4*pi*t)
38-
ax1 = subplot(311)
39-
plot(t, s1)
40-
setp(ax1.get_xticklabels(), fontsize=6)
39+
ax1 = plt.subplot(311)
40+
plt.plot(t, s1)
41+
plt.setp(ax1.get_xticklabels(), fontsize=6)
4142

4243
# share x only
43-
ax2 = subplot(312, sharex=ax1)
44-
plot(t, s2)
44+
ax2 = plt.subplot(312, sharex=ax1)
45+
plt.plot(t, s2)
4546
# make these tick labels invisible
46-
setp(ax2.get_xticklabels(), visible=False)
47+
plt.setp(ax2.get_xticklabels(), visible=False)
4748

4849
# share x and y
49-
ax3 = subplot(313, sharex=ax1, sharey=ax1)
50-
plot(t, s3)
51-
xlim(0.01, 5.0)
52-
show()
50+
ax3 = plt.subplot(313, sharex=ax1, sharey=ax1)
51+
plt.plot(t, s3)
52+
plt.xlim(0.01, 5.0)
53+
plt.show()
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from pylab import *
1+
import matplotlib.pyplot as plt
2+
import numpy as np
23

3-
t = arange(0.0, 2.0, 0.01)
4-
s = sin(2*pi*t)
5-
plot(t, s)
4+
t = np.arange(0.0, 2.0, 0.01)
5+
s = np.sin(2*np.pi*t)
6+
plt.plot(t, s)
67

7-
xlabel('time (s)')
8-
ylabel('voltage (mV)')
9-
title('About as simple as it gets, folks')
10-
grid(True)
11-
savefig("test.png")
12-
show()
8+
plt.xlabel('time (s)')
9+
plt.ylabel('voltage (mV)')
10+
plt.title('About as simple as it gets, folks')
11+
plt.grid(True)
12+
plt.savefig("test.png")
13+
plt.show()

examples/pylab_examples/simple_plot_fps.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
#!/usr/bin/env python
2-
31
"""
42
Example: simple line plot.
53
Show how to make and save a simple line plot with labels, title and grid
64
"""
7-
# -*- noplot -*-
8-
from __future__ import print_function
9-
from pylab import *
5+
from __future__ import print_function # not necessary in Python 3.x
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
import time
109

11-
ion()
1210

13-
t = arange(0.0, 1.0 + 0.001, 0.001)
14-
s = cos(2*2*pi*t)
15-
plot(t, s, '-', lw=2)
11+
plt.ion()
1612

17-
xlabel('time (s)')
18-
ylabel('voltage (mV)')
19-
title('About as simple as it gets, folks')
20-
grid(True)
13+
t = np.arange(0.0, 1.0 + 0.001, 0.001)
14+
s = np.cos(2*2*np.pi*t)
15+
plt.plot(t, s, '-', lw=2)
2116

22-
import time
17+
plt.xlabel('time (s)')
18+
plt.ylabel('voltage (mV)')
19+
plt.title('About as simple as it gets, folks')
20+
plt.grid(True)
2321

2422
frames = 100.0
2523
t = time.time()
2624
c = time.clock()
2725
for i in range(int(frames)):
2826
part = i / frames
29-
axis([0.0, 1.0 - part, -1.0 + part, 1.0 - part])
27+
plt.axis([0.0, 1.0 - part, -1.0 + part, 1.0 - part])
3028
wallclock = time.time() - t
3129
user = time.clock() - c
3230
print("wallclock:", wallclock)
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#!/usr/bin/env python
2-
from pylab import *
1+
import matplotlib.pyplot as plt
2+
import numpy as np
33

44
dt = 0.0005
5-
t = arange(0.0, 20.0, dt)
6-
s1 = sin(2*pi*100*t)
7-
s2 = 2*sin(2*pi*400*t)
5+
t = np.arange(0.0, 20.0, dt)
6+
s1 = np.sin(2*np.pi*100*t)
7+
s2 = 2*np.sin(2*np.pi*400*t)
88

99
# create a transient "chirp"
10-
mask = where(logical_and(t > 10, t < 12), 1.0, 0.0)
10+
mask = np.where(np.logical_and(t > 10, t < 12), 1.0, 0.0)
1111
s2 = s2 * mask
1212

1313
# add some noise into the mix
14-
nse = 0.01*randn(len(t))
14+
nse = 0.01*np.random.random(size=len(t))
1515

1616
x = s1 + s2 + nse # the signal
1717
NFFT = 1024 # the length of the windowing segments
@@ -22,9 +22,9 @@
2222
# the power is computed, and im is the matplotlib.image.AxesImage
2323
# instance
2424

25-
ax1 = subplot(211)
26-
plot(t, x)
27-
subplot(212, sharex=ax1)
28-
Pxx, freqs, bins, im = specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900,
29-
cmap=cm.gist_heat)
30-
show()
25+
ax1 = plt.subplot(211)
26+
plt.plot(t, x)
27+
plt.subplot(212, sharex=ax1)
28+
Pxx, freqs, bins, im = plt.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900,
29+
cmap=plt.cm.gist_heat)
30+
plt.show()
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
#!/usr/bin/env python
2-
# python
3-
4-
from pylab import *
1+
import matplotlib.pyplot as plt
2+
import numpy as np
53

64
dt = 0.01
75
Fs = 1/dt
8-
t = arange(0, 10, dt)
9-
nse = randn(len(t))
10-
r = exp(-t/0.05)
6+
t = np.arange(0, 10, dt)
7+
nse = np.random.randn(len(t))
8+
r = np.exp(-t/0.05)
119

12-
cnse = convolve(nse, r)*dt
10+
cnse = np.convolve(nse, r)*dt
1311
cnse = cnse[:len(t)]
14-
s = 0.1*sin(2*pi*t) + cnse
12+
s = 0.1*np.sin(2*np.pi*t) + cnse
1513

16-
subplot(3, 2, 1)
17-
plot(t, s)
14+
plt.subplot(3, 2, 1)
15+
plt.plot(t, s)
1816

19-
subplot(3, 2, 3)
20-
magnitude_spectrum(s, Fs=Fs)
17+
plt.subplot(3, 2, 3)
18+
plt.magnitude_spectrum(s, Fs=Fs)
2119

22-
subplot(3, 2, 4)
23-
magnitude_spectrum(s, Fs=Fs, scale='dB')
20+
plt.subplot(3, 2, 4)
21+
plt.magnitude_spectrum(s, Fs=Fs, scale='dB')
2422

25-
subplot(3, 2, 5)
26-
angle_spectrum(s, Fs=Fs)
23+
plt.subplot(3, 2, 5)
24+
plt.angle_spectrum(s, Fs=Fs)
2725

28-
subplot(3, 2, 6)
29-
phase_spectrum(s, Fs=Fs)
26+
plt.subplot(3, 2, 6)
27+
plt.phase_spectrum(s, Fs=Fs)
3028

31-
show()
29+
plt.show()

0 commit comments

Comments
 (0)