working on colors and tests

This commit is contained in:
Thomas Breloff 2015-10-20 14:49:01 -04:00
parent d1e9cc5800
commit 546955a78b
31 changed files with 129 additions and 104 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*.jl.mem
.DS_Store
examples/.ipynb_checkpoints/*
examples/meetup/.ipynb_checkpoints/*

View File

@ -633,16 +633,16 @@ function buildGadflySubplotContext(subplt::Subplot)
Gadfly.vstack(rows...)
end
function setGadflyDisplaySize(w,h)
Compose.set_default_graphic_size(w * Compose.px, h * Compose.px)
end
setGadflyDisplaySize(w,h) = Compose.set_default_graphic_size(w * Compose.px, h * Compose.px)
setGadflyDisplaySize(plt::Plot) = setGadflyDisplaySize(plt.initargs[:size]...)
setGadflyDisplaySize(subplt::Subplot) = setGadflyDisplaySize(getinitargs(subplt, 1)[:size]...)
# -------------------------------------------------------------------------
function dowritemime{P<:GadflyOrImmerse}(io::IO, func, plt::PlottingObject{P})
gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt.initargs[:size]...)
# setGadflyDisplaySize(plt.initargs[:size]...)
setGadflyDisplaySize(plt)
Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
@ -670,7 +670,7 @@ end
function Base.display(::PlotsDisplay, subplt::Subplot{GadflyPackage})
setGadflyDisplaySize(subplt.initargs[1][:size]...)
setGadflyDisplaySize(getinitargs(subplt,1)[:size]...)
ctx = buildGadflySubplotContext(subplt)

View File

@ -92,7 +92,7 @@ function buildSubplotObject!(subplt::Subplot{ImmersePackage}, isbefore::Bool)
isbefore && return false
# create the Gtk window with vertical box vsep
d = subplt.initargs[1]
d = getinitargs(subplt,1)
w,h = d[:size]
vsep = Gtk.GtkBoxLeaf(:v)
win = Gtk.GtkWindowLeaf(vsep, d[:windowtitle], w, h)

View File

@ -497,8 +497,8 @@ end
function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
l = subplt.layout
w,h = map(px2inch, subplt.initargs[1][:size])
bgcolor = getPyPlotColor(subplt.initargs[1][:background_color])
w,h = map(px2inch, getinitargs(subplt,1)[:size])
bgcolor = getPyPlotColor(getinitargs(subplt,1)[:background_color])
fig = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96)
nr = nrows(l)

View File

@ -278,7 +278,7 @@ function buildSubplotObject!(subplt::Subplot{QwtPackage}, isbefore::Bool)
# i += rowcnt
# end
subplt.o = Qwt.vsplitter(rows...)
Qwt.resizewidget(subplt.o, subplt.initargs[1][:size]...)
Qwt.resizewidget(subplt.o, getinitargs(subplt,1)[:size]...)
Qwt.moveToLastScreen(subplt.o) # hack so it goes to my center monitor... sorry
true
end

View File

@ -105,6 +105,8 @@ colorscheme(m::AMat) = size(m,1) == 1 ? map(colorscheme, m) : [colorscheme(m[:,i
colorscheme(c::Colorant) = ColorWrapper(c)
const _rainbowColors = [colorant"blue", colorant"purple", colorant"green", colorant"orange", colorant"red"]
const _testColors = [colorant"darkblue", colorant"blueviolet", colorant"darkcyan",colorant"green",
darken(colorant"yellow",0.3), colorant"orange", darken(colorant"red",0.2)]
@compat const _gradients = Dict(
:blues => [colorant"lightblue", colorant"darkblue"],
@ -117,6 +119,8 @@ const _rainbowColors = [colorant"blue", colorant"purple", colorant"green", color
:rainbow => _rainbowColors,
:lightrainbow => map(lighten, _rainbowColors),
:darkrainbow => map(darken, _rainbowColors),
:darktest => _testColors,
:lighttest => map(c -> lighten(c, 0.3), _testColors),
)
# --------------------------------------------------------------
@ -305,7 +309,8 @@ end
function getPaletteUsingGradientSymbol(palette, bgcolor::Colorant, numcolors::Int = _defaultNumColors) #; gradientsym::Symbol = :auto)
# @show gradientsym
if palette == :auto
grad = ColorGradient(_gradients[isdark(bgcolor) ? :lightrainbow : :darkrainbow])
# grad = ColorGradient(_gradients[isdark(bgcolor) ? :lightrainbow : :darkrainbow])
grad = ColorGradient(_gradients[isdark(bgcolor) ? :lighttest : :darktest])
# elseif typeof(palette) <: AVec || typeof(palette) <: ColorGradient
# grad = ColorGradient(palette)
else

View File

@ -167,11 +167,14 @@ function subplot(args...; kw...)
# initialize the individual plots
pkg = backend()
plts = Plot[]
ds = Dict[]
# ds = Dict[]
for i in 1:length(layout)
push!(ds, getPlotArgs(pkg, d, i))
ds[i][:subplot] = true
push!(plts, plot(pkg; ds[i]...))
di = getPlotArgs(pkg, d, i)
di[:subplot] = true
push!(plts, plot(pkg; di...))
# push!(ds, getPlotArgs(pkg, d, i))
# ds[i][:subplot] = true
# push!(plts, plot(pkg; ds[i]...))
end
# tmpd = getPlotKeywordArgs(pkg, kw, 1, 0) # TODO: this should happen in the plot creation loop... think... what if we want to set a title per subplot??
@ -181,7 +184,8 @@ function subplot(args...; kw...)
# # tmpd[:show] = shouldShow
# create the object and do the plotting
subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, ds, false, false, false, (r,c) -> (nothing,nothing))
# subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, ds, false, false, false, (r,c) -> (nothing,nothing))
subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, d, false, false, false, (r,c) -> (nothing,nothing))
subplot!(subplt, args...; kw...)
subplt

View File

@ -38,7 +38,8 @@ type Subplot{T<:PlottingPackage, L<:SubplotLayout} <: PlottingObject{T}
p::Int # number of plots
n::Int # number of series
layout::L
initargs::Vector{Dict}
# initargs::Vector{Dict}
initargs::Dict
initialized::Bool
linkx::Bool
linky::Bool

View File

@ -6,3 +6,5 @@ FactCheck
PyPlot
UnicodePlots
Gadfly
Images
ImageMagick

View File

@ -16,8 +16,8 @@ include("../docs/example_generation.jl")
# plt
# end
using Plots
import Images, Gtk, ImageMagick
using Plots, FactCheck
import Images, ImageMagick
function makeImageWidget(fn)
img = Gtk.GtkImageLeaf(fn)
@ -29,11 +29,14 @@ function makeImageWidget(fn)
end
function replaceReferenceImage(tmpfn, reffn)
println("cp $tmpfn $reffn")
cmd = `cp $tmpfn $reffn`
run(cmd)
info("Replaced reference image with: $cmd")
end
"Show a Gtk popup with both images and a confirmation whether we should replace the new image with the old one"
function compareToReferenceImage(tmpfn, reffn)
@eval import Gtk
# add the images
imgbox = Gtk.GtkBoxLeaf(:h)
@ -51,7 +54,8 @@ function compareToReferenceImage(tmpfn, reffn)
box = Gtk.GtkBoxLeaf(:v)
push!(box, imgbox)
push!(box, btnbox)
win = Gtk.GtkWindowLeaf(Gtk.GtkFrameLeaf(box))
win = Gtk.GtkWindowLeaf("Should we make this the new reference image?")
push!(win, Gtk.GtkFrameLeaf(box))
# we'll wait on this condition
c = Condition()
@ -76,7 +80,7 @@ end
# TODO: use julia's Condition type and the wait() and notify() functions to initialize a Window, then wait() on a condition that
# is referenced in a button press callback (the button clicked callback will call notify() on that condition)
function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,0], eps = 1e-3)
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, sigma = [1,1], eps = 1e-3)
# first
Plots._debugMode.on = debug
@ -84,7 +88,10 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,
backend(pkg)
backend()
info("here: ", PlotExamples.examples[idx].exprs)
# ensure consistent results
srand(1234)
# run the example
map(eval, PlotExamples.examples[idx].exprs)
# save the png
@ -97,7 +104,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,
# reference image location
refdir = joinpath(Pkg.dir("Plots"), "test", "refimg", "v$(VERSION.major).$(VERSION.minor)", string(pkg))
try
mkdir(refdir)
run(`mkdir -p $refdir`)
catch err
display(err)
end
@ -105,7 +112,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,
try
info("Comparing $tmpfn to reference $reffn")
# info("Comparing $tmpfn to reference $reffn")
# load the reference image
refimg = Images.load(reffn)
@ -115,10 +122,16 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,
# to blur together when comparing images
Images.@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps)
# we passed!
info("Reference image $reffn matches")
return true
catch ex
warn("Image did not match reference image $reffn")
if isinteractive()
# if we're in interactive mode, open a popup and give us a chance to examine the images
warn("Should we make this the new reference image?")
compareToReferenceImage(tmpfn, reffn)
return
@ -131,13 +144,9 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,
end
end
function image_comparison_tests(pkg::Symbol; debug = false)
function image_comparison_tests(pkg::Symbol; skip = [], debug = false, sigma = [1,1], eps = 1e-3)
for i in 1:length(PlotExamples.examples)
# try
image_comparison_tests(pkgname, i, debug=debug)
# catch ex
# # TODO: put error info into markdown?
# warn("Example $pkgname:$i:$(examples[i].header) failed with: $ex")
# end
i in skip && continue
@fact image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) --> true
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -3,11 +3,17 @@ module PlotsTests
using Plots
using FactCheck
# note: wrap first include in a try block because of the ImageMagick init_deps bug
try
include("imgcomp.jl")
end
include("imgcomp.jl")
# don't actually show the plots
srand(1234)
# note: we wrap in a try block so that the tests only run if we have the backend installed
try
# try
Pkg.installed("Gadfly")
gadfly()
backend()
@ -28,60 +34,55 @@ try
# plot(x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y))
@fact plot!(rand(10,3), rand(10,3)) --> not(nothing)
# @fact_throws plot!(rand(10,3), rand(10,2))
image_comparison_tests(:gadfly, skip=[19])
# plot(x::AVec, y::AVec{AVec}; kw...) # multiple lines, will assert length(x) == length(y[i])
# plot(x::AVec{AVec}, y::AVec{AVec}; kw...) # multiple lines, will assert length(x[i]) == length(y[i])
# plot(n::Integer; kw...) # n lines, all empty (for updating plots)
end
catch err
warn("Skipped Gadfly due to: ", string(err))
end
# catch err
# warn("Skipped Gadfly due to: ", string(err))
# end
# note: we wrap in a try block so that the tests only run if we have the backend installed
try
Pkg.installed("Qwt")
qwt()
backend()
facts("Qwt") do
@fact backend(:qwt) --> Plots.QwtPackage()
@fact backend() --> Plots.QwtPackage()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.QwtPackage}
# # note: we wrap in a try block so that the tests only run if we have the backend installed
# try
# Pkg.installed("Qwt")
# qwt()
# backend()
# facts("Qwt") do
# @fact backend(:qwt) --> Plots.QwtPackage()
# @fact backend() --> Plots.QwtPackage()
# @fact typeof(plot(1:10)) --> Plots.Plot{Plots.QwtPackage}
# plot(y::AVec; kw...) # one line... x = 1:length(y)
@fact plot(1:10) --> not(nothing)
@fact length(current().o.lines) --> 1
# # plot(y::AVec; kw...) # one line... x = 1:length(y)
# @fact plot(1:10) --> not(nothing)
# @fact length(current().o.lines) --> 1
# plot(x::AVec, f::Function; kw...) # one line, y = f(x)
@fact plot(1:10, sin) --> not(nothing)
@fact current().o.lines[1].y --> sin(collect(1:10))
# # plot(x::AVec, f::Function; kw...) # one line, y = f(x)
# @fact plot(1:10, sin) --> not(nothing)
# @fact current().o.lines[1].y --> sin(collect(1:10))
# plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ)
@fact plot(rand(10,2), sin) --> not(nothing)
@fact length(current().o.lines) --> 2
# # plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ)
# @fact plot(rand(10,2), sin) --> not(nothing)
# @fact length(current().o.lines) --> 2
# plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1)
@fact plot!(rand(10,2)) --> not(nothing)
@fact length(current().o.lines) --> 4
# # plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1)
# @fact plot!(rand(10,2)) --> not(nothing)
# @fact length(current().o.lines) --> 4
# plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ)
@fact plot(1:10, Function[sin,cos]) --> not(nothing)
@fact current().o.lines[1].y --> sin(collect(1:10))
@fact current().o.lines[2].y --> cos(collect(1:10))
# # plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ)
# @fact plot(1:10, Function[sin,cos]) --> not(nothing)
# @fact current().o.lines[1].y --> sin(collect(1:10))
# @fact current().o.lines[2].y --> cos(collect(1:10))
# plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i])
@fact plot([11:20 ; rand(10)]) --> not(nothing)
@fact current().o.lines[1].x[4] --> 4
@fact current().o.lines[1].y[4] --> 14
end
catch err
warn("Skipped Qwt due to: ", string(err))
end
# # plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i])
# @fact plot([11:20 ; rand(10)]) --> not(nothing)
# @fact current().o.lines[1].x[4] --> 4
# @fact current().o.lines[1].y[4] --> 14
# end
# catch err
# warn("Skipped Qwt due to: ", string(err))
# end
try
# try
Pkg.installed("PyPlot")
pyplot()
backend()
@ -89,38 +90,40 @@ try
@fact backend(:pyplot) --> Plots.PyPlotPackage()
@fact backend() --> Plots.PyPlotPackage()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.PyPlotPackage}
image_comparison_tests(:pyplot, skip=[19])
end
catch err
warn("Skipped PyPlot due to: ", string(err))
end
# catch err
# warn("Skipped PyPlot due to: ", string(err))
# end
try
Pkg.installed("UnicodePlots")
unicodeplots()
backend()
facts("UnicodePlots") do
@fact backend(:unicodeplots) --> Plots.UnicodePlotsPackage()
@fact backend() --> Plots.UnicodePlotsPackage()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.UnicodePlotsPackage}
end
catch err
warn("Skipped UnicodePlots due to: ", string(err))
end
# try
# Pkg.installed("UnicodePlots")
# unicodeplots()
# backend()
# facts("UnicodePlots") do
# @fact backend(:unicodeplots) --> Plots.UnicodePlotsPackage()
# @fact backend() --> Plots.UnicodePlotsPackage()
# @fact typeof(plot(1:10)) --> Plots.Plot{Plots.UnicodePlotsPackage}
# end
# catch err
# warn("Skipped UnicodePlots due to: ", string(err))
# end
try
Pkg.installed("Winston")
winston()
backend()
facts("Winston") do
@fact backend(:winston) --> Plots.WinstonPackage()
@fact backend() --> Plots.WinstonPackage()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.WinstonPackage}
end
catch err
warn("Skipped Winston due to: ", string(err))
end
# try
# Pkg.installed("Winston")
# winston()
# backend()
# facts("Winston") do
# @fact backend(:winston) --> Plots.WinstonPackage()
# @fact backend() --> Plots.WinstonPackage()
# @fact typeof(plot(1:10)) --> Plots.Plot{Plots.WinstonPackage}
# end
# catch err
# warn("Skipped Winston due to: ", string(err))
# end
FactCheck.exitstatus()