diff --git a/REQUIRE b/REQUIRE index e126e43..dd93ddd 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.3 +julia 0.4 Compat ArgParse Docile diff --git a/examples/julia_sample.pdf b/examples/julia_sample.pdf index 71cd2c5..39e11f7 100644 Binary files a/examples/julia_sample.pdf and b/examples/julia_sample.pdf differ diff --git a/src/pyplot.jl b/src/pyplot.jl index 9cdb3ab..9ecf7b1 100644 --- a/src/pyplot.jl +++ b/src/pyplot.jl @@ -1,13 +1,14 @@ using PyPlot -function savefigs_pyplot(chunk, report::Report) +function savefigs_pyplot(report::Report) + chunk = report.cur_chunk fignames = AbstractString[] ext = report.formatdict[:fig_ext] figpath = joinpath(report.cwd, chunk.options[:fig_path]) isdir(figpath) || mkdir(figpath) chunkid = (chunk.options[:name] == nothing) ? chunk.number : chunk.options[:name] #Iterate over all open figures, save them and store names - #info("Saving figs") + for fig = plt[:get_fignums]() full_name, rel_name = get_figname(report, chunk, fignum=fig) diff --git a/src/run.jl b/src/run.jl index 8e7f2de..73bd30c 100644 --- a/src/run.jl +++ b/src/run.jl @@ -102,16 +102,17 @@ function run_code(chunk::CodeChunk, report::Report, SandBox::Module) for (str_expr, expr) = expressions reset_report(report) (obj, out) = capture_output(expr, SandBox, chunk.options[:term], rcParams[:plotlib]) - - if rcParams[:plotlib] == "pyplot" - savefigs_pyplot(chunk, report::Report) - end - displayed = report.cur_result #Not needed? figures = report.figures #Captured figures result = ChunkOutput(str_expr, out, displayed, figures) push!(results, result) end + + #Save figures only in the end of chunk for PyPlot + if rcParams[:plotlib] == "PyPlot" + savefigs_pyplot(report::Report) + end + return results end @@ -354,7 +355,7 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult) content = "" result_no = 1 result_chunks = CodeChunk[ ] - for r =chunk.result + for r = chunk.result if strip(r.stdout) == "" && isempty(r.figures) && r.displayed == "" content *= r.code else @@ -369,7 +370,8 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult) end end if content != "" - rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options)) + startswith(content, "\n") || (content = "\n" * content) + rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options)) push!(result_chunks, rchunk) end diff --git a/test/REQUIRE b/test/REQUIRE index ef42477..f57c0ce 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,5 +1,4 @@ -julia 0.3 +julia 0.4 Cairo Gadfly -Winston -PyPlot \ No newline at end of file +PyPlot diff --git a/test/documents/pyplot_formats_ref.md b/test/documents/pyplot_formats_ref.md index f6aae03..656b5a5 100644 --- a/test/documents/pyplot_formats_ref.md +++ b/test/documents/pyplot_formats_ref.md @@ -24,19 +24,18 @@ plot(x, sin(x)) ````julia julia> x = linspace(0, 2π, 200) + linspace(0.0,6.283185307179586,200) - julia> plot(x, sin(x)) + 1-element Array{Any,1}: - PyObject - + PyObject julia> y = 20 -20 +20 julia> plot(x, cos(x)) 1-element Array{Any,1}: - PyObject - + PyObject ```` diff --git a/test/documents/pyplot_formats_ref.rst b/test/documents/pyplot_formats_ref.rst index 36743f9..2e9373c 100644 --- a/test/documents/pyplot_formats_ref.rst +++ b/test/documents/pyplot_formats_ref.rst @@ -34,21 +34,20 @@ .. code-block:: julia - - julia> x = linspace(0, 2π, 200) - linspace(0.0,6.283185307179586,200) - - julia> plot(x, sin(x)) - 1-element Array{Any,1}: - PyObject - - julia> y = 20 - 20 - - julia> plot(x, cos(x)) - 1-element Array{Any,1}: - PyObject +julia> x = linspace(0, 2π, 200) + +linspace(0.0,6.283185307179586,200) +julia> plot(x, sin(x)) + +1-element Array{Any,1}: + PyObject +julia> y = 20 + +20 +julia> plot(x, cos(x)) +1-element Array{Any,1}: + PyObject diff --git a/test/documents/pyplot_formats_ref.tex b/test/documents/pyplot_formats_ref.tex index f8e72d5..114a06c 100644 --- a/test/documents/pyplot_formats_ref.tex +++ b/test/documents/pyplot_formats_ref.tex @@ -3,16 +3,29 @@ -\begin{juliacode}using PyPlot +\begin{juliacode} +using PyPlot x = linspace(0, 2π, 200) plot(x, sin(x)) \end{juliacode} +\begin{figure}[ht] +\center +\includegraphics[width=\linewidth]{figures/pyplot_formats_sin_fun_1.pdf} +\caption{sin(x) function.} +\label{fig:sin_fun} +\end{figure} +\begin{figure}[htpb] +\center +\includegraphics[width=\linewidth]{figures/pyplot_formats_2_1.pdf} +\caption{cos(x) function.} +\end{figure} +\includegraphics[width=\linewidth]{figures/pyplot_formats_cos2_fun_1.pdf} @@ -23,17 +36,20 @@ linspace(0.0,6.283185307179586,200) julia> plot(x, sin(x)) 1-element Array{Any,1}: - PyObject + PyObject julia> y = 20 20 julia> plot(x, cos(x)) 1-element Array{Any,1}: - PyObject + PyObject \end{juliaterm} +\includegraphics[width=\linewidth]{figures/pyplot_formats_4_1.pdf} -\begin{juliacode}x = randn(100, 100) +\begin{juliacode} +x = randn(100, 100) contourf(x) \end{juliacode} +\includegraphics[width=15cm]{figures/pyplot_formats_5_1.pdf} diff --git a/test/pyplot_formats.jl b/test/pyplot_formats.jl index 9046534..0375b78 100644 --- a/test/pyplot_formats.jl +++ b/test/pyplot_formats.jl @@ -6,8 +6,8 @@ cleanup = true weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="tex") result = readall(open("documents/pyplot_formats.tex")) ref = readall(open("documents/pyplot_formats_ref.tex")) -result = replace(result, r"\s*PyObject.*\n", "") #Remove PyObjects, because they change -ref = replace(ref, r"\s*PyObject.*\n", "") +result = replace(result, r"\s*PyObject.*\n", "\n") #Remove PyObjects, because they change +ref = replace(ref, r"\s*PyObject.*\n", "\n") @test result == ref weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="github") @@ -31,4 +31,3 @@ if cleanup rm("documents/pyplot_formats.md") rm("documents/figures", recursive = true) end - diff --git a/test/runtests.jl b/test/runtests.jl index b938843..0aed431 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,18 +9,17 @@ using Base.Test info("Test: Chunk options") include("chunk_options.jl") -# Cache is not implemented for new output format +# Cache is currently not implemented for new output format #info("Test: Caching") #include("cache_test.jl") +# Winston support not updated for 0.4 +# info("Test: Weaving with Winston") +# include("winston_formats.jl") -if VERSION.minor == 3 - info("Test: Weaving with Winston") - include("winston_formats.jl") -end info("Test: Weaving with Gadfly") include("gadfly_formats.jl") -#info("Test: Weaving with PyPlot") -#include("pyplot_formats.jl") +info("Test: Weaving with PyPlot") +include("pyplot_formats.jl")