Skip to content

Commit

Permalink
re-enable travis (#379)
Browse files Browse the repository at this point in the history
* re-enable travis

* fix Base.showable in Julia 0.6

* debugging output in Pkg.test

* fixes for matplotlib 1.3, remove Base64 dependency

* agg backend on 1.3 doesn't seem to support ps output properly

* viridis is not available in matplotlib 1.3
  • Loading branch information
stevengj authored Aug 27, 2018
1 parent 3bd36da commit 8eeecf4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 11 additions & 4 deletions src/PyPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down
41 changes: 23 additions & 18 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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-")

Expand All @@ -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 ]

0 comments on commit 8eeecf4

Please sign in to comment.