Skip to content

Commit 1297a42

Browse files
committed
Cleanup Winston plots and histograms in examples
1 parent 0f6d627 commit 1297a42

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

demos/book/1/bellcurve.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@
99
t=1000000
1010
dx=.2
1111
v=randn(t)
12-
count=hist(v,[-4-dx/2:dx:4+dx/2])
13-
count/=sum(count)*dx
12+
grid=[-4:dx:4]
13+
count=hist(v,grid)/(t*dx)
1414

1515
## Theory
16-
x=[-4:dx:4]
16+
x=grid
1717
y=exp(-x.^2/2)/sqrt(2*pi)
1818

1919
## Plot
20-
#XXX Currently Histogram() must start plotting from 0.
21-
#For now, add offset to theoretical curve
22-
#Filed: https://github.com/nolta/Winston.jl/issues/28
23-
#cjh 2013-03-16
2420
using Winston
2521
p = FramedPlot()
26-
add(p, Histogram(count, dx))
27-
add(p, Curve(x+4+dx/2, y, "color", "blue", "linewidth", 2))
22+
h = Histogram(count, dx)
23+
h.x0 = grid[1]
24+
add(p, h)
25+
add(p, Curve(x, y, "color", "blue", "linewidth", 2))
2826
file(p, "bellcurve.png")

demos/book/1/largeeig.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ n=100 # matrix size
1212
t=5000 # trials
1313
v=[] # eigenvalue samples
1414
dx=.2 # binsize
15+
grid=[-5:dx:2]
1516
## Experiment
1617
for i=1:t
1718
a=randn(n,n)+im*randn(n,n) # random nxn complex matrix
@@ -20,20 +21,17 @@ for i=1:t
2021
end
2122
v=n^(1/6)*(v-2*sqrt(n)) # normalized eigenvalues
2223

23-
count=hist(v,-5:dx:2)
24-
count/=t*dx
24+
count=hist(v,grid)/(t*dx)
2525

2626
## Theory
2727
(t, f) = tracywidom(5., -8.)
2828

2929
## Plot
30-
#XXX Currently Histogram() must start plotting from 0.
31-
#For now, add offset to theoretical curve
32-
#Filed: https://github.com/nolta/Winston.jl/issues/28
33-
#cjh 2013-03-16
3430
using Winston
3531
p = FramedPlot()
36-
add(p, Histogram(count, dx))
32+
h = Histogram(count, dx)
33+
h.x0 = grid[1]
34+
add(p, h)
3735
add(p, Curve(t+5, f, "linewidth", 2, "color", "blue"))
3836
file(p, "largeeig.png")
3937

demos/book/1/semicircle.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ n=1000 # matrix size
99
t=10 # trials
1010
v=[] # eigenvalue samples
1111
dx=.2 # binsize
12+
grid=[-2.4:dx:2.4]
1213
## Experiment
1314
for i = 1:t
1415
a=randn(n,n) # n by n matrix of random Gaussians
1516
s=(a+a')/sqrt(2*n)# symmetrize and normalize matrix
1617
v=[v;eig(s)[1]] # eigenvalues
1718
end
18-
count=hist(v,-2.4:dx:2.4)
19-
count/=n*t*dx
19+
count=hist(grid)/(n*t*dx)
2020
## Theory
2121
x=[-2:dx:2]
2222
y=sqrt(4-x.^2)/(2*pi)
2323

2424
## Plot
2525
using Winston
2626
p = FramedPlot()
27-
add(p, Histogram(count, dx))
27+
h = Histogram(count, dx)
28+
h.x0 = grid[1]
29+
add(p, h)
2830
add(p, Curve(x+2.4+dx/2, y, "color", "blue", "linewidth", 2))
2931
file(p, "semicircle.png")

0 commit comments

Comments
 (0)