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

Skip to content

Commit 446a7c8

Browse files
committed
users guide updates
svn path=/trunk/matplotlib/; revision=585
1 parent bbb2592 commit 446a7c8

File tree

7 files changed

+221
-152
lines changed

7 files changed

+221
-152
lines changed

TODO

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,6 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
587587

588588
-- Humufr errobar
589589

590-
-- why is tkagg loading init 2x
590+
-- why is tkagg loading init 2x
591+
592+
-- add ishold and spy

examples/anscombe.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
"""
3+
Edward Tufte uses this example from Anscombe to show 4 datasets of x
4+
and y that have the same mean, standard deviation, and regression
5+
line, but which are qualitatively different.
6+
7+
matplotlib fun for a rainy day
8+
"""
9+
10+
from matplotlib.matlab import *
11+
12+
x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
13+
y1 = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
14+
y2 = array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74])
15+
y3 = array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73])
16+
x4 = array([8,8,8,8,8,8,8,19,8,8,8])
17+
y4 = array([6.58,5.76,7.71,8.84,8.47,7.04,5.25,12.50,5.56,7.91,6.89])
18+
19+
def fit(x):
20+
return 3+0.5*x
21+
22+
23+
24+
xfit = array( [min(x), max(x) ] )
25+
26+
subplot(221)
27+
plot(x,y1,'ks', xfit, fit(xfit), 'r-', lw=2)
28+
axis([2,20,2,14])
29+
set(gca(), xticklabels=[], yticks=(4,8,12), xticks=(0,10,20))
30+
text(3,12, 'I', fontsize=20)
31+
32+
subplot(222)
33+
plot(x,y2,'ks', xfit, fit(xfit), 'r-', lw=2)
34+
axis([2,20,2,14])
35+
set(gca(), xticklabels=[], yticks=(4,8,12), yticklabels=[], xticks=(0,10,20))
36+
text(3,12, 'II', fontsize=20)
37+
38+
subplot(223)
39+
plot(x,y3,'ks', xfit, fit(xfit), 'r-', lw=2)
40+
axis([2,20,2,14])
41+
text(3,12, 'IIII', fontsize=20)
42+
set(gca(), yticks=(4,8,12), xticks=(0,10,20))
43+
44+
subplot(224)
45+
46+
xfit = array([min(x4),max(x4)])
47+
plot(x4,y4,'ks', xfit, fit(xfit), 'r-', lw=2)
48+
axis([2,20,2,14])
49+
set(gca(), yticklabels=[], yticks=(4,8,12), xticks=(0,10,20))
50+
text(3,12, 'IV', fontsize=20)
51+
52+
#verify the stats
53+
pairs = (x,y1), (x,y2), (x,y3), (x4,y4)
54+
for x,y in pairs:
55+
print 'mean=%1.2f, std=%1.2f, r=%1.2f'%(mean(y), std(y), corrcoef(x,y)[0][1])
56+
57+
show()

examples/specgram_demo.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
#!/usr/bin/env python
22
from matplotlib.matlab import *
33

4-
54
dt = 0.0005
65
t = arange(0.0, 20.0, dt)
76
s1 = sin(2*pi*100*t)
87
s2 = 2*sin(2*pi*400*t)
8+
9+
# create a transient "chirp"
910
mask = where(logical_and(t>10, t<12), 1.0, 0.0)
1011
s2 = s2 * mask
12+
13+
# add some noise into the mix
1114
nse = 0.01*randn(len(t))
12-
x = s1 + s2 + nse
13-
NFFT = 1024
14-
Fs = int(1.0/dt)
15-
Noverlap = 0
15+
16+
x = s1 + s2 + nse # the signal
17+
NFFT = 1024 # the length of the windowing segments
18+
Fs = int(1.0/dt) # the sampling frequency
19+
20+
# Pxx is the segments x freqs array of instantaneous power, freqs is
21+
# the frequency vector, bins are the centers of the time bins in which
22+
# the power is computed, and im is the matplotlib.image.AxesImage
23+
# instance
1624
Pxx, freqs, bins, im = specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900)
1725
colorbar()
1826
show()

0 commit comments

Comments
 (0)