From bbe797fcc8191f540f4aab3a823b536ba1a7b8e7 Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Wed, 20 Apr 2016 22:19:01 +0300 Subject: [PATCH] Improved examples --- README.md | 13 ++++++- examples/gadfly_md_sample.jmd | 70 +++++++++++++++++++++++++++++++++++ examples/gadfly_sample.jmd | 30 --------------- examples/gadfly_sample.mdw | 31 ++++++++++++---- 4 files changed, 105 insertions(+), 39 deletions(-) create mode 100644 examples/gadfly_md_sample.jmd delete mode 100644 examples/gadfly_sample.jmd diff --git a/README.md b/README.md index 41ee627..2d499a8 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,19 @@ You can write your documentation and code in input document using Nowed or Markd Run from julia using Gadfly for plots: -````julia +```julia using Weave weave(Pkg.dir("Weave","examples","gadfly_sample.mdw")) -```` +``` + +If you have Pandoc installed you can also weave directly to html and pdf. + +```julia +weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown", + out_path = :pwd, doctype = "md2html") +``` + +![Weave code and output](http://mpastell.com/images/weave_demo.png) ## Documentation diff --git a/examples/gadfly_md_sample.jmd b/examples/gadfly_md_sample.jmd new file mode 100644 index 0000000..7188c6f --- /dev/null +++ b/examples/gadfly_md_sample.jmd @@ -0,0 +1,70 @@ +% Intro to Weave.jl with Gadfly +% Matti Pastell +% 20th April 2016 + +# Introduction + +This a sample [Julia](http://julialang.org/) noweb document that can +be executed using [Weave.jl](https://github.com/mpastell/Weave.jl). + +The code is delimited from docs using markdown fenced code blocks +markup which can be seen looking at the source document [gadfly_md_sample.jmd](gadfly_md_sample.jmd) +in the examples directory of the package. The source document can be executed + and the results with Gadfly plots are captured in the resulting file. + +You can create markdown output or pdf and HTML directly (with Pandoc) using +the weave command as follows: + +```{julia; eval=false} +using Weave +#Markdown +weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown", + out_path = :pwd, doctype = "pandoc") +#HTML +weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown", + out_path = :pwd, doctype = "md2html") +#pdf +weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown", + out_path = :pwd, doctype = "md2pdf") +``` + +*The documents will be written to the Julia working directory when you +use the `out_path = :pwd`.* + +# Capturing code + +The basic code chunk will be run with default options and the code and +output will be captured. + +```julia +using Gadfly +x = linspace(0, 2*pi) +println(x) +plot(x = x, y = sin(x)) +``` + +You can also control the way the results are captured, plot size etc. +using chunk options. Here is an example of a chunk that behaves like a repl. + +```{julia;term=true} +x = 1:10 +d = Dict("Weave" => "testing") +y = [2, 4 ,8] +``` + +You can also for instance hide the code and show only the figure, add a +caption to the figure and make it wider as follows (you can only see the +syntax from the source document): + +```{julia;echo=false; fig_cap="A random walk."; label="random"; fig_width=8; fig_height=4} +plot(y = cumsum(randn(1000, 1)), Geom.line) +``` + +# Whats next + +Read the documentation: + + - stable: + - latest: + +See other examples in: diff --git a/examples/gadfly_sample.jmd b/examples/gadfly_sample.jmd deleted file mode 100644 index 8c2ba0d..0000000 --- a/examples/gadfly_sample.jmd +++ /dev/null @@ -1,30 +0,0 @@ - -# Gadfly - -```{julia;term=true;fig_width=5} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -y = 20 -plot(x=x, y = cos(x), Geom.line) -``` - - -```julia -x = linspace(0, 200) -println(x) -``` - - -~~~{julia;term=true;fig_width=5} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -y = 20 -plot(x=x, y = cos(x), Geom.line) -~~~ - -~~~julia -x = linspace(0, 200) -println(x) -~~~ diff --git a/examples/gadfly_sample.mdw b/examples/gadfly_sample.mdw index f3d94c9..99d468e 100644 --- a/examples/gadfly_sample.mdw +++ b/examples/gadfly_sample.mdw @@ -8,7 +8,7 @@ This a sample [Julia](http://julialang.org/) noweb document that can be executed using [Weave.jl](https://github.com/mpastell/Weave.jl). The code is delimited from docs using `<<>>=` and `@` markup which can be seen -looking at the source document [gadfly_sample.mdw] in the examples directory +looking at the source document `gadfly_sample.mdw` in the examples directory of the package. The source document can be executed and the results with Gadfly plots are captured in the resulting file. @@ -37,17 +37,34 @@ The basic code chunk will be run with default options and the code and output will be captured. <<>>= -Using Gadfly +using Gadfly x = linspace(0, 2*pi) println(x) plot(x = x, y = sin(x)) @ - +You can also control the way the results are captured, plot size etc. +using chunk options. Here is an example of a chunk that behaves like a repl. <>= -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -y = 20 -plot(x=x, y = cos(x), Geom.line) +x = 1:10 +d = Dict("Weave" => "testing") +y = [2, 4 ,8] @ + +You can also for instance hide the code and show only the figure, add a +caption to the figure and make it wider as follows (you can only see the +syntax from the source document): + +<>= +plot(y = cumsum(randn(1000, 1)), Geom.line) +@ + +# Whats next + +Read the documentation: + + - stable: + - latest: + +See other examples in: