Skip to content

Commit 8eeecf4

Browse files
authored
re-enable travis (#379)
* 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
1 parent 3bd36da commit 8eeecf4

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: julia
2+
os:
3+
- linux
4+
julia:
5+
- 0.6
6+
- 0.7
7+
- 1.0
8+
- nightly
9+
addons:
10+
apt:
11+
packages:
12+
- python-matplotlib
13+
- python3-matplotlib
14+
env:
15+
matrix:
16+
- PYTHON=python # python 2.7
17+
- PYTHON=python3 # python 3.5
18+
notifications:
19+
email: false

src/PyPlot.jl

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ module PyPlot
44

55
using PyCall
66
import PyCall: PyObject, pygui, pycall, pyexists
7-
import Base: convert, ==, isequal, hash, getindex, setindex!, haskey, keys, show, showable
7+
import Base: convert, ==, isequal, hash, getindex, setindex!, haskey, keys, show
88
export Figure, plt, matplotlib, pygui, withfig
99

1010
using Compat
1111
import Base.show
1212

13-
1413
###########################################################################
1514
# Julia 0.4 help system: define a documentation object
1615
# that lazily looks up help from a PyObject via zero or more keys.
@@ -78,14 +77,22 @@ for (mime,fmt) in aggformats
7877
f.o["canvas"]["print_figure"](io, format=$fmt, bbox_inches="tight")
7978
end
8079
if fmt != "svg"
81-
@eval showable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt)
80+
if isdefined(Base, :showable)
81+
@eval Base.showable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt)
82+
else
83+
@eval Base.mimewritable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt)
84+
end
8285
end
8386
end
8487

8588
# disable SVG output by default, since displaying large SVGs (large datasets)
8689
# in IJulia is slow, and browser SVG display is buggy. (Similar to IPython.)
8790
const SVG = [false]
88-
showable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg")
91+
if isdefined(Base, :showable)
92+
Base.showable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg")
93+
else
94+
Base.mimewritable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg")
95+
end
8996
svg() = SVG[1]
9097
svg(b::Bool) = (SVG[1] = b)
9198

test/runtests.jl

+23-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using PyPlot, PyCall
44
using Compat
55
using Compat.Test
66

7-
VERSION >= v"0.7.0" && using Base64
7+
Compat.@info("PyPlot is using Matplotlib $(PyPlot.version) with Python $(PyCall.pyversion)")
88

99
plot(1:5, 2:6, "ro-")
1010

@@ -14,23 +14,28 @@ line = gca()[:lines][1]
1414

1515
fig = gcf()
1616
@test isa(fig, PyPlot.Figure)
17-
@test fig[:get_size_inches]() [6.4, 4.8]
18-
19-
s = stringmime("application/postscript", fig);
20-
m = match(r"%%BoundingBox: *([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+)", s)
21-
@test m !== nothing
22-
boundingbox = map(s -> parse(Int, s), m.captures)
23-
Compat.@info("got plot bounding box ", boundingbox)
24-
@test all([300, 200] .< boundingbox[3:4] - boundingbox[1:2] .< [450,350])
25-
26-
c = get_cmap("viridis")
17+
if PyPlot.version >= v"2"
18+
@test fig[:get_size_inches]() [6.4, 4.8]
19+
else # matplotlib 1.3
20+
@test fig[:get_size_inches]() [8, 6]
21+
end
22+
23+
# with Matplotlib 1.3, I get "UserWarning: bbox_inches option for ps backend is not implemented yet"
24+
if PyPlot.version >= v"2"
25+
s = sprint(show, "application/postscript", fig);
26+
m = match(r"%%BoundingBox: *([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+)", s)
27+
@test m !== nothing
28+
boundingbox = map(s -> parse(Int, s), m.captures)
29+
Compat.@info("got plot bounding box ", boundingbox)
30+
@test all([300, 200] .< boundingbox[3:4] - boundingbox[1:2] .< [450,350])
31+
end
32+
33+
c = get_cmap("RdBu")
2734
a = 0.0:0.25:1.0
28-
29-
3035
rgba = pycall(pycall(PyPlot.ScalarMappable, PyObject, cmap=c,
3136
norm=PyPlot.Normalize01)["to_rgba"], PyArray, a)
32-
@test rgba [ 0.267004 0.004874 0.329415 1.0
33-
0.229739 0.322361 0.545706 1.0
34-
0.127568 0.566949 0.550556 1.0
35-
0.369214 0.788888 0.382914 1.0
36-
0.993248 0.906157 0.143936 1.0 ]
37+
@test rgba [ 0.403921568627451 0.0 0.12156862745098039 1.0
38+
0.8991926182237601 0.5144175317185697 0.4079200307574009 1.0
39+
0.9657054978854287 0.9672433679354094 0.9680891964628989 1.0
40+
0.4085351787773935 0.6687427912341408 0.8145328719723184 1.0
41+
0.0196078431372549 0.18823529411764706 0.3803921568627451 1.0 ]

0 commit comments

Comments
 (0)