Weave.jl/examples/winston_sample.mdw

58 lines
1.2 KiB
Plaintext
Raw Normal View History

2014-12-01 20:23:35 +01:00
# Introducion to Weave
2014-12-01 20:23:35 +01:00
This a sample [Julia](http://julialang.org/) noweb document that can
be executed using Weave. Output from code chunks and Winston
plots will be included in the weaved document. You also need to install Pweave from Github in order to use Weave.
2014-12-01 20:23:35 +01:00
This documented can be turned into Pandoc markdown with captured
result from Julia prompt.
~~~~{.julia}
using Weave
weave(Pkg.dir("Weave","examples","winston_sample.mdw"), plotlib="Winston")
2014-12-01 20:23:35 +01:00
~~~~
## Terminal chunk
<<term=true>>=
2014-12-01 20:23:35 +01:00
x = 1:10
d = Dict("Weave" => "testing")
2014-12-01 20:23:35 +01:00
y = [2, 4 ,8]
@
## Capturing figures
The figures and code can be included in the output.
2014-12-04 16:54:56 +01:00
<<term=true>>=
2014-12-01 20:23:35 +01:00
using Winston
t = linspace(0, 2*pi, 100)
2014-12-04 16:54:56 +01:00
p = plot(t, sinc(t))
2014-12-01 20:23:35 +01:00
@
You can also include a plot with caption and hide the code:
2014-12-04 21:10:24 +01:00
<<echo=false; fig_cap="Random walk."; label="random"; fig_width=8; fig_height=4>>=
2014-12-04 16:54:56 +01:00
p = plot(cumsum(randn(1000, 1)))
xlabel("x")
ylabel("sinc(x)")
display(p)
2014-12-01 20:23:35 +01:00
@
2014-12-04 15:14:07 +01:00
<<>>=
x = linspace(0, 3pi, 100)
c = cos(x)
s = sin(x)
p = FramedPlot(
title="title!",
xlabel="\\Sigma x^2_i",
ylabel="\\Theta_i")
add(p, FillBetween(x, c, x, s))
add(p, Curve(x, c, color="red"))
add(p, Curve(x, s, color="blue"))
2014-12-04 16:54:56 +01:00
display(p)
2014-12-04 15:14:07 +01:00
@