Fixed output format and tests for PyPlot

pull/35/head
Matti Pastell 2016-04-12 17:08:29 +03:00
parent 6ab22417bf
commit 8a35d741f6
10 changed files with 61 additions and 47 deletions

View File

@ -1,4 +1,4 @@
julia 0.3
julia 0.4
Compat
ArgParse
Docile

Binary file not shown.

View File

@ -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)

View File

@ -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

View File

@ -1,5 +1,4 @@
julia 0.3
julia 0.4
Cairo
Gadfly
Winston
PyPlot
PyPlot

View File

@ -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 <matplotlib.lines.Line2D object at 0x7f702c979c10>
PyObject <matplotlib.lines.Line2D object at 0x7f11ccf03a10>
julia> y = 20
20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f702c979e90>
PyObject <matplotlib.lines.Line2D object at 0x7f11ccf03410>
````

View File

@ -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 <matplotlib.lines.Line2D object at 0x7f702b4e15d0>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f702b4e1850>
julia> x = linspace(0, 2π, 200)
linspace(0.0,6.283185307179586,200)
julia> plot(x, sin(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f995cdeae90>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f995cdf9b90>

View File

@ -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 <matplotlib.lines.Line2D object at 0x7f2eac1dca90>
PyObject <matplotlib.lines.Line2D object at 0x7f84f5e74750>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f2eac1f3650>
PyObject <matplotlib.lines.Line2D object at 0x7f84f5e74950>
\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}

View File

@ -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

View File

@ -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")