diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..c53d7d78 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: julia +os: + - linux +julia: + - 0.6 + - 0.7 + - 1.0 + - nightly +addons: + apt: + packages: + - python-matplotlib + - python3-matplotlib +env: + matrix: + - PYTHON=python # python 2.7 + - PYTHON=python3 # python 3.5 +notifications: + email: false diff --git a/src/PyPlot.jl b/src/PyPlot.jl index 99e03645..3f40272d 100755 --- a/src/PyPlot.jl +++ b/src/PyPlot.jl @@ -4,13 +4,12 @@ module PyPlot using PyCall import PyCall: PyObject, pygui, pycall, pyexists -import Base: convert, ==, isequal, hash, getindex, setindex!, haskey, keys, show, showable +import Base: convert, ==, isequal, hash, getindex, setindex!, haskey, keys, show export Figure, plt, matplotlib, pygui, withfig using Compat import Base.show - ########################################################################### # Julia 0.4 help system: define a documentation object # that lazily looks up help from a PyObject via zero or more keys. @@ -78,14 +77,22 @@ for (mime,fmt) in aggformats f.o["canvas"]["print_figure"](io, format=$fmt, bbox_inches="tight") end if fmt != "svg" - @eval showable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt) + if isdefined(Base, :showable) + @eval Base.showable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt) + else + @eval Base.mimewritable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt) + end end end # disable SVG output by default, since displaying large SVGs (large datasets) # in IJulia is slow, and browser SVG display is buggy. (Similar to IPython.) const SVG = [false] -showable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg") +if isdefined(Base, :showable) + Base.showable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg") +else + Base.mimewritable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg") +end svg() = SVG[1] svg(b::Bool) = (SVG[1] = b) diff --git a/test/runtests.jl b/test/runtests.jl index 80df47d9..504be64d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,7 @@ using PyPlot, PyCall using Compat using Compat.Test -VERSION >= v"0.7.0" && using Base64 +Compat.@info("PyPlot is using Matplotlib $(PyPlot.version) with Python $(PyCall.pyversion)") plot(1:5, 2:6, "ro-") @@ -14,23 +14,28 @@ line = gca()[:lines][1] fig = gcf() @test isa(fig, PyPlot.Figure) -@test fig[:get_size_inches]() ≈ [6.4, 4.8] - -s = stringmime("application/postscript", fig); -m = match(r"%%BoundingBox: *([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+)", s) -@test m !== nothing -boundingbox = map(s -> parse(Int, s), m.captures) -Compat.@info("got plot bounding box ", boundingbox) -@test all([300, 200] .< boundingbox[3:4] - boundingbox[1:2] .< [450,350]) - -c = get_cmap("viridis") +if PyPlot.version >= v"2" + @test fig[:get_size_inches]() ≈ [6.4, 4.8] +else # matplotlib 1.3 + @test fig[:get_size_inches]() ≈ [8, 6] +end + +# with Matplotlib 1.3, I get "UserWarning: bbox_inches option for ps backend is not implemented yet" +if PyPlot.version >= v"2" + s = sprint(show, "application/postscript", fig); + m = match(r"%%BoundingBox: *([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+)", s) + @test m !== nothing + boundingbox = map(s -> parse(Int, s), m.captures) + Compat.@info("got plot bounding box ", boundingbox) + @test all([300, 200] .< boundingbox[3:4] - boundingbox[1:2] .< [450,350]) +end + +c = get_cmap("RdBu") a = 0.0:0.25:1.0 - - rgba = pycall(pycall(PyPlot.ScalarMappable, PyObject, cmap=c, norm=PyPlot.Normalize01)["to_rgba"], PyArray, a) -@test rgba ≈ [ 0.267004 0.004874 0.329415 1.0 - 0.229739 0.322361 0.545706 1.0 - 0.127568 0.566949 0.550556 1.0 - 0.369214 0.788888 0.382914 1.0 - 0.993248 0.906157 0.143936 1.0 ] +@test rgba ≈ [ 0.403921568627451 0.0 0.12156862745098039 1.0 + 0.8991926182237601 0.5144175317185697 0.4079200307574009 1.0 + 0.9657054978854287 0.9672433679354094 0.9680891964628989 1.0 + 0.4085351787773935 0.6687427912341408 0.8145328719723184 1.0 + 0.0196078431372549 0.18823529411764706 0.3803921568627451 1.0 ] \ No newline at end of file