mirror of https://github.com/mpastell/Weave.jl
Fix Plots.jl PyPlot backend saving and update tests
parent
10e089379b
commit
7bccdd2ab1
|
@ -32,7 +32,7 @@ function Base.display(report::Report, data)
|
||||||
try
|
try
|
||||||
display(report, m, data)
|
display(report, m, data)
|
||||||
catch
|
catch
|
||||||
info(m)
|
warn("Failed to save image in \"$m\" format")
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
#Always show plain text as well for term mode
|
#Always show plain text as well for term mode
|
||||||
|
@ -45,21 +45,15 @@ function Base.display(report::Report, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.display(report::Report, m::MIME"image/png", data)
|
function Base.display(report::Report, m::MIME"image/png", data)
|
||||||
figname = add_figure(report, ".png")
|
figname = add_figure(report, data, m, ".png")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.display(report::Report, m::MIME"image/svg+xml", data)
|
function Base.display(report::Report, m::MIME"image/svg+xml", data)
|
||||||
figname = add_figure(report, ".svg")
|
figname = add_figure(report, data, m, ".svg")
|
||||||
open(figname, "w") do io
|
|
||||||
show(io, m, data)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.display(report::Report, m::MIME"application/pdf", data)
|
function Base.display(report::Report, m::MIME"application/pdf", data)
|
||||||
figname = add_figure(report, ".pdf")
|
figname = add_figure(report, m, data, ".pdf")
|
||||||
open(figname, "w") do io
|
|
||||||
show(io, m, data)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#Text is written to stdout, called from "term" mode chunks
|
#Text is written to stdout, called from "term" mode chunks
|
||||||
|
@ -87,7 +81,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
"""Add saved figure name to results and return the name"""
|
"""Add saved figure name to results and return the name"""
|
||||||
function add_figure(report::Report, ext)
|
function add_figure(report::Report, data, m, ext)
|
||||||
chunk = report.cur_chunk
|
chunk = report.cur_chunk
|
||||||
full_name, rel_name = get_figname(report, chunk, ext = ext)
|
full_name, rel_name = get_figname(report, chunk, ext = ext)
|
||||||
|
|
||||||
|
|
24
src/plots.jl
24
src/plots.jl
|
@ -53,3 +53,27 @@ function Base.display(report::Report, m::MIME"image/png", plot::Plots.Plot{Plots
|
||||||
|
|
||||||
report.rich_output *= "\n" * body
|
report.rich_output *= "\n" * body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
"""Add saved figure name to results and return the name"""
|
||||||
|
function add_pyplot_figure(report::Report, plot::Plots.Plot{Plots.PyPlotBackend}, ext)
|
||||||
|
chunk = report.cur_chunk
|
||||||
|
full_name, rel_name = get_figname(report, chunk, ext = ext)
|
||||||
|
|
||||||
|
Plots.savefig(plot, full_name)
|
||||||
|
push!(report.figures, rel_name)
|
||||||
|
report.fignum += 1
|
||||||
|
return full_name
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(report::Report, m::MIME"application/pdf", plot::Plots.Plot{Plots.PyPlotBackend})
|
||||||
|
add_pyplot_figure(report, plot, ".pdf")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(report::Report, m::MIME"image/png", plot::Plots.Plot{Plots.PyPlotBackend})
|
||||||
|
add_pyplot_figure(report, plot, ".png")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(report::Report, m::MIME"image/svg+xml", plot::Plots.Plot{Plots.PyPlotBackend})
|
||||||
|
add_pyplot_figure(report, plot, ".svg")
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
using Plots
|
||||||
|
pyplot()
|
||||||
|
x = linspace(0, 2*pi)
|
||||||
|
println(x)
|
||||||
|
p = plot(x = x, y = sin(x), size =(900,300))
|
||||||
|
|
||||||
|
plot(x = x, y = sin(x))
|
||||||
|
|
||||||
|
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||||
|
scatter!(rand(100),markersize=6,c=:orange)
|
||||||
|
|
||||||
|
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||||
|
scatter!(rand(100),markersize=6,c=:orange)
|
||||||
|
|
||||||
|
plot(y = cumsum(randn(1000, 1)))
|
|
@ -20,10 +20,7 @@ p = plot(x = x, y = sin(x), size =(900,300))
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
~~~~
|
![](figures/plotsjl_test_1_1.png)\
|
||||||
[Plots.jl] Initializing backend: pyplot
|
|
||||||
~~~~
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,12 +28,14 @@ p = plot(x = x, y = sin(x), size =(900,300))
|
||||||
|
|
||||||
~~~~{.julia}
|
~~~~{.julia}
|
||||||
julia> plot(x = x, y = sin(x))
|
julia> plot(x = x, y = sin(x))
|
||||||
Plot{Plots.PyPlotBackend() n=1}
|
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
![](figures/plotsjl_test_2_1.png)\
|
![](figures/plotsjl_test_2_1.png)\
|
||||||
|
|
||||||
|
![](figures/plotsjl_test_2_1.png)\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,13 +47,15 @@ scatter!(rand(100),markersize=6,c=:orange)
|
||||||
|
|
||||||
![](figures/plotsjl_test_3_1.png)\
|
![](figures/plotsjl_test_3_1.png)\
|
||||||
|
|
||||||
|
![](figures/plotsjl_test_3_1.png)\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
~~~~{.julia}
|
~~~~{.julia}
|
||||||
julia> plot(rand(100) / 3,reg=true,fill=(0,:green))
|
julia> plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||||
|
|
||||||
Plot{Plots.PyPlotBackend() n=1}
|
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,14 +64,17 @@ Plot{Plots.PyPlotBackend() n=1}
|
||||||
|
|
||||||
~~~~{.julia}
|
~~~~{.julia}
|
||||||
julia> scatter!(rand(100),markersize=6,c=:orange)
|
julia> scatter!(rand(100),markersize=6,c=:orange)
|
||||||
Plot{Plots.PyPlotBackend() n=2}
|
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
![](figures/plotsjl_test_4_2.png)\
|
![](figures/plotsjl_test_4_2.png)\
|
||||||
|
|
||||||
|
![](figures/plotsjl_test_4_1.png)\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
![A random walk.](figures/plotsjl_test_random_1.png)
|
![A random walk.](figures/plotsjl_test_random_1.png)
|
||||||
|
![](figures/plotsjl_test_random_1.png)
|
||||||
|
|
|
@ -20,7 +20,7 @@ p = plot(x = x, y = sin(x), size =(900,300))
|
||||||
|
|
||||||
\begin{juliaterm}
|
\begin{juliaterm}
|
||||||
julia> plot(x = x, y = sin(x))
|
julia> plot(x = x, y = sin(x))
|
||||||
Plot{Plots.PyPlotBackend() n=1}
|
|
||||||
\end{juliaterm}
|
\end{juliaterm}
|
||||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_2_1.pdf}
|
\includegraphics[width=\linewidth]{figures/plotsjl_test_2_1.pdf}
|
||||||
|
|
||||||
|
@ -37,13 +37,13 @@ scatter!(rand(100),markersize=6,c=:orange)
|
||||||
\begin{juliaterm}
|
\begin{juliaterm}
|
||||||
julia> plot(rand(100) / 3,reg=true,fill=(0,:green))
|
julia> plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||||
|
|
||||||
Plot{Plots.PyPlotBackend() n=1}
|
|
||||||
\end{juliaterm}
|
\end{juliaterm}
|
||||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_4_1.pdf}
|
\includegraphics[width=\linewidth]{figures/plotsjl_test_4_1.pdf}
|
||||||
|
|
||||||
\begin{juliaterm}
|
\begin{juliaterm}
|
||||||
julia> scatter!(rand(100),markersize=6,c=:orange)
|
julia> scatter!(rand(100),markersize=6,c=:orange)
|
||||||
Plot{Plots.PyPlotBackend() n=2}
|
|
||||||
\end{juliaterm}
|
\end{juliaterm}
|
||||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_4_2.pdf}
|
\includegraphics[width=\linewidth]{figures/plotsjl_test_4_2.pdf}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ plot(x, sin(x))
|
||||||
|
|
||||||
````
|
````
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f5326a4a290>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a20a84780>
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ plot(x, sin(x))
|
||||||
|
|
||||||
````
|
````
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f5326a56c10>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a208be780>
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ plot(x, sin(x))
|
||||||
|
|
||||||
````
|
````
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f5326d76350>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a207f5c50>
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,17 +42,18 @@ plot(x, sin(x))
|
||||||
````julia
|
````julia
|
||||||
julia> x = linspace(0, 2π, 200)
|
julia> x = linspace(0, 2π, 200)
|
||||||
|
|
||||||
linspace(0.0,6.283185307179586,200)
|
200-element LinSpace{Float64}:
|
||||||
|
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
|
||||||
julia> plot(x, sin(x))
|
julia> plot(x, sin(x))
|
||||||
|
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f5326de8c10>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a207da518>
|
||||||
julia> y = 20
|
julia> y = 20
|
||||||
|
|
||||||
20
|
20
|
||||||
julia> plot(x, cos(x))
|
julia> plot(x, cos(x))
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f5326de8e50>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a207da780>
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ contourf(x)
|
||||||
|
|
||||||
|
|
||||||
````
|
````
|
||||||
PyObject <matplotlib.contour.QuadContourSet object at 0x7f53346d2910>
|
PyObject <matplotlib.contour.QuadContourSet object at 0x7f6a1980e0f0>
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
::
|
::
|
||||||
|
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f9745111450>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a209bb518>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
::
|
::
|
||||||
|
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f9777e49990>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a2099c3c8>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
::
|
::
|
||||||
|
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f9777d7b590>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a20e59780>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,17 +57,18 @@
|
||||||
|
|
||||||
julia> x = linspace(0, 2π, 200)
|
julia> x = linspace(0, 2π, 200)
|
||||||
|
|
||||||
linspace(0.0,6.283185307179586,200)
|
200-element LinSpace{Float64}:
|
||||||
|
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
|
||||||
julia> plot(x, sin(x))
|
julia> plot(x, sin(x))
|
||||||
|
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f9777c71190>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a19819208>
|
||||||
julia> y = 20
|
julia> y = 20
|
||||||
|
|
||||||
20
|
20
|
||||||
julia> plot(x, cos(x))
|
julia> plot(x, cos(x))
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7f9777c71390>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a209aed68>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ julia> plot(x, cos(x))
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
PyObject <matplotlib.contour.QuadContourSet object at 0x7f9777ba3510>
|
PyObject <matplotlib.contour.QuadContourSet object at 0x7f6a193c6668>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ plot(x, sin(x))
|
||||||
\end{juliacode}
|
\end{juliacode}
|
||||||
\begin{juliaout}
|
\begin{juliaout}
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7fe847179cd0>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a2109f6a0>
|
||||||
\end{juliaout}
|
\end{juliaout}
|
||||||
\begin{figure}[ht]
|
\begin{figure}[ht]
|
||||||
\center
|
\center
|
||||||
|
@ -22,7 +22,7 @@ plot(x, sin(x))
|
||||||
|
|
||||||
\begin{juliaout}
|
\begin{juliaout}
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7fe846fb2950>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a20f34e48>
|
||||||
\end{juliaout}
|
\end{juliaout}
|
||||||
\begin{figure}[htpb]
|
\begin{figure}[htpb]
|
||||||
\center
|
\center
|
||||||
|
@ -34,7 +34,7 @@ plot(x, sin(x))
|
||||||
|
|
||||||
\begin{juliaout}
|
\begin{juliaout}
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7fe839790510>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a20e48b70>
|
||||||
\end{juliaout}
|
\end{juliaout}
|
||||||
\includegraphics[width=\linewidth]{figures/pyplot_formats_cos2_fun_1.pdf}
|
\includegraphics[width=\linewidth]{figures/pyplot_formats_cos2_fun_1.pdf}
|
||||||
|
|
||||||
|
@ -43,17 +43,18 @@ plot(x, sin(x))
|
||||||
\begin{juliaterm}
|
\begin{juliaterm}
|
||||||
julia> x = linspace(0, 2π, 200)
|
julia> x = linspace(0, 2π, 200)
|
||||||
|
|
||||||
linspace(0.0,6.283185307179586,200)
|
200-element LinSpace{Float64}:
|
||||||
|
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
|
||||||
julia> plot(x, sin(x))
|
julia> plot(x, sin(x))
|
||||||
|
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7fe8396c8110>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a20dad160>
|
||||||
julia> y = 20
|
julia> y = 20
|
||||||
|
|
||||||
20
|
20
|
||||||
julia> plot(x, cos(x))
|
julia> plot(x, cos(x))
|
||||||
1-element Array{Any,1}:
|
1-element Array{Any,1}:
|
||||||
PyObject <matplotlib.lines.Line2D object at 0x7fe8396c8310>
|
PyObject <matplotlib.lines.Line2D object at 0x7f6a20e9ce80>
|
||||||
\end{juliaterm}
|
\end{juliaterm}
|
||||||
\includegraphics[width=\linewidth]{figures/pyplot_formats_4_1.pdf}
|
\includegraphics[width=\linewidth]{figures/pyplot_formats_4_1.pdf}
|
||||||
|
|
||||||
|
@ -64,6 +65,6 @@ x = randn(100, 100)
|
||||||
contourf(x)
|
contourf(x)
|
||||||
\end{juliacode}
|
\end{juliacode}
|
||||||
\begin{juliaout}
|
\begin{juliaout}
|
||||||
PyObject <matplotlib.contour.QuadContourSet object at 0x7fe8395fc390>
|
PyObject <matplotlib.contour.QuadContourSet object at 0x7f6a20adb1d0>
|
||||||
\end{juliaout}
|
\end{juliaout}
|
||||||
\includegraphics[width=15cm]{figures/pyplot_formats_5_1.pdf}
|
\includegraphics[width=15cm]{figures/pyplot_formats_5_1.pdf}
|
||||||
|
|
|
@ -2,7 +2,7 @@ using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
function pljtest(source, resfile, doctype)
|
function pljtest(source, resfile, doctype)
|
||||||
weave("documents/$source", out_path = "documents/plotsjl/$resfile", doctype=doctype, plotlib=nothing)
|
weave("documents/$source", out_path = "documents/plotsjl/$resfile", doctype=doctype)
|
||||||
result = @compat readstring(open("documents/plotsjl/$resfile"))
|
result = @compat readstring(open("documents/plotsjl/$resfile"))
|
||||||
ref = @compat readstring(open("documents/plotsjl/$resfile.ref"))
|
ref = @compat readstring(open("documents/plotsjl/$resfile.ref"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
|
@ -26,8 +26,8 @@ include("gadfly_formats.jl")
|
||||||
#include("winston_formats.jl")
|
#include("winston_formats.jl")
|
||||||
|
|
||||||
# Output changed, needs fixing for 0.5
|
# Output changed, needs fixing for 0.5
|
||||||
#info("Test: Weaving with PyPlot")
|
info("Test: Weaving with PyPlot")
|
||||||
#include("pyplot_formats.jl")
|
include("pyplot_formats.jl")
|
||||||
|
|
||||||
#info("Test: Weaving with Plots.jl")
|
info("Test: Weaving with Plots.jl")
|
||||||
#include("plotsjl_test.jl")
|
include("plotsjl_test.jl")
|
||||||
|
|
Loading…
Reference in New Issue