diff --git a/img/gadfly/gadfly_example_2.gif b/img/gadfly/gadfly_example_2.gif index 30919f43..dcc5b833 100644 Binary files a/img/gadfly/gadfly_example_2.gif and b/img/gadfly/gadfly_example_2.gif differ diff --git a/img/pyplot/pyplot_example_2.gif b/img/pyplot/pyplot_example_2.gif index 53ae8668..89ad3b2a 100644 Binary files a/img/pyplot/pyplot_example_2.gif and b/img/pyplot/pyplot_example_2.gif differ diff --git a/img/qwt/qwt_example_2.gif b/img/qwt/qwt_example_2.gif index 956a413f..beeb8fa0 100644 Binary files a/img/qwt/qwt_example_2.gif and b/img/qwt/qwt_example_2.gif differ diff --git a/src/args.jl b/src/args.jl index 1b9900c4..36d6cc2a 100644 --- a/src/args.jl +++ b/src/args.jl @@ -345,7 +345,6 @@ trueOrAllTrue(f::Function, x) = f(x) function handleColors!(d::Dict, arg, csym::Symbol) try - # @show arg typeof(arg) if arg == :auto d[csym] = :auto else @@ -353,8 +352,6 @@ function handleColors!(d::Dict, arg, csym::Symbol) d[csym] = c end return true - # catch err - # dump(err) end false end @@ -372,7 +369,6 @@ function processAxisArg(d::Dict, axisletter::@compat(AbstractString), arg) elseif arg in (:flip, :invert, :inverted) d[symbol(axisletter * "flip")] = true - # end elseif T <: @compat(AbstractString) d[symbol(axisletter * "label")] = arg diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 7a69301e..6f5df7e6 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -144,7 +144,7 @@ function addGadflyMarker!(plt::Plot, d::Dict, initargs::Dict, geoms...) if !isa(d[:markercolor], ColorGradient) d[:markercolor] = colorscheme(:bluesreds) end - push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:markercolor], p)))) + push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGBA(getColorZ(d[:markercolor], p)))) end Gadfly.layer(gfargs...; x = d[:x], y = d[:y], kwargs...) diff --git a/src/colors.jl b/src/colors.jl index 393d8cdf..bf2f4d6d 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -87,6 +87,13 @@ convertColor(c::@compat(Union{AbstractString, Symbol})) = parse(Colorant, string convertColor(c::Colorant) = c convertColor(cvec::AbstractVector) = map(convertColor, cvec) +function convertColor(c, α::Real) + c = convertColor(c) + RGBA(c, α) +end +convertColor(cs::AVec, α::Real) = map(c -> convertColor(c, α), cs) +convertColor(c, α::Void) = convertColor(c) + # backup... try to convert getColor(c) = convertColor(c) @@ -98,14 +105,14 @@ getColor(scheme::ColorScheme) = getColor(scheme, 1) getColorVector(scheme::ColorScheme) = [getColor(scheme)] colorscheme(scheme::ColorScheme) = scheme -colorscheme(s::Symbol) = haskey(_gradients, s) ? ColorGradient(s) : ColorWrapper(convertColor(s)) -colorscheme{T<:Real}(s::Symbol, vals::AVec{T}) = ColorGradient(s, vals) -colorscheme(cs::AVec, vs::AVec) = ColorGradient(cs, vs) -colorscheme{T<:Colorant}(cs::AVec{T}) = ColorGradient(cs) -colorscheme(f::Function) = ColorFunction(f) -colorscheme(v::AVec) = ColorVector(v) -colorscheme(m::AMat) = size(m,1) == 1 ? map(colorscheme, m) : [colorscheme(m[:,i]) for i in 1:size(m,2)]' -colorscheme(c::Colorant) = ColorWrapper(c) +colorscheme(s::Symbol; kw...) = haskey(_gradients, s) ? ColorGradient(s; kw...) : ColorWrapper(convertColor(s); kw...) +colorscheme{T<:Real}(s::Symbol, vals::AVec{T}; kw...) = ColorGradient(s, vals; kw...) +colorscheme(cs::AVec, vs::AVec; kw...) = ColorGradient(cs, vs; kw...) +colorscheme{T<:Colorant}(cs::AVec{T}; kw...) = ColorGradient(cs; kw...) +colorscheme(f::Function; kw...) = ColorFunction(f; kw...) +colorscheme(v::AVec; kw...) = ColorVector(v; kw...) +colorscheme(m::AMat; kw...) = size(m,1) == 1 ? map(c->colorscheme(c; kw...), m) : [colorscheme(m[:,i]; kw...) for i in 1:size(m,2)]' +colorscheme(c::Colorant; kw...) = ColorWrapper(c; kw...) # -------------------------------------------------------------- @@ -138,23 +145,29 @@ immutable ColorGradient <: ColorScheme colors::Vector{Colorant} values::Vector{Float64} - function ColorGradient{T<:Colorant,S<:Real}(cs::AVec{T}, vals::AVec{S} = 0:1) - length(cs) == length(vals) && return new(cs, collect(vals)) + function ColorGradient{T<:Colorant,S<:Real}(cs::AVec{T}, vals::AVec{S} = 0:1; alpha = nothing) + if length(cs) == length(vals) + return new(convertColor(cs,alpha), collect(vals)) + end # otherwise interpolate evenly between the minval and maxval minval, maxval = minimum(vals), maximum(vals) vs = Float64[interpolate(minval, maxval, w) for w in linspace(0, 1, length(cs))] - new(cs, vs) + new(convertColor(cs,alpha), vs) end end # create a gradient from a symbol (blues, reds, etc) and vector of boundary values -function ColorGradient{T<:Real}(s::Symbol, vals::AVec{T} = 0:1) +function ColorGradient{T<:Real}(s::Symbol, vals::AVec{T} = 0:1; kw...) haskey(_gradients, s) || error("Invalid gradient symbol. Choose from: ", sort(collect(keys(_gradients)))) # if we passed in the right number of values, create the gradient directly cs = _gradients[s] - ColorGradient(cs, vals) + ColorGradient(cs, vals; kw...) +end + +function ColorGradient{T<:Real}(cs::AVec{Symbol}, vals::AVec{T} = 0:1; kw...) + ColorGradient(map(convertColor, cs), vals; kw...) end getColor(gradient::ColorGradient, idx::Int) = gradient.colors[mod1(idx, length(gradient.colors))] @@ -225,7 +238,7 @@ getColorZ(scheme::ColorFunction, z::Real) = scheme.f(z) "Wraps a vector of colors... may be vector of Symbol/String/Colorant" immutable ColorVector <: ColorScheme v::Vector{Colorant} - ColorVector(v::AVec) = new(convertColor(v)) + ColorVector(v::AVec; alpha = nothing) = new(convertColor(v,alpha)) end getColor(scheme::ColorVector, idx::Int) = convertColor(scheme.v[mod1(idx, length(scheme.v))]) @@ -235,11 +248,12 @@ getColorVector(scheme::ColorVector) = scheme.v # -------------------------------------------------------------- "Wraps a single color" -immutable ColorWrapper{C<:Colorant} <: ColorScheme - c::C +immutable ColorWrapper <: ColorScheme + c::RGBA + ColorWrapper(c::Colorant; alpha = nothing) = new(convertColor(c, alpha)) end -ColorWrapper(s::Symbol) = ColorWrapper(parse(Colorant, s)) +ColorWrapper(s::Symbol; alpha = nothing) = ColorWrapper(convertColor(parse(Colorant, s), alpha)) getColor(scheme::ColorWrapper, idx::Int) = scheme.c getColorZ(scheme::ColorWrapper, z::Real) = scheme.c @@ -290,19 +304,19 @@ const _lightness_lightbg = [60.0] const _lch_c_const = [60] function adjust_lch(color, l, c) - lch = convert(LCHab,color) + lch = convert(LCHab, color) convert(RGB, LCHab(l, c, lch.h)) end function lightness_from_background(bgcolor) - bglight = convert(LCHab,bgcolor).l + bglight = convert(LCHab, bgcolor).l bglight < 50.0 ? _lightness_darkbg[1] : _lightness_lightbg[1] end function gradient_from_list(cs) zvalues = Plots.get_zvalues(length(cs)) indices = sortperm(zvalues) - sorted_colors = map(RGB, cs[indices]) + sorted_colors = map(RGBA, cs[indices]) sorted_zvalues = zvalues[indices] ColorGradient(sorted_colors, sorted_zvalues) end diff --git a/src/plotter.jl b/src/plotter.jl index 0481b42f..b1e1fa9f 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -160,12 +160,19 @@ function backend() @eval const pypath = PyPlot.pywrap(PyPlot.pyimport("matplotlib.path")) # @eval const pycolorbar = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colorbar")) if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay) - PyPlot.ioff() + PyPlot.ioff() # stops wierd behavior of displaying incomplete graphs in IJulia + + # # TODO: how the hell can I use PyQt4?? # "pyqt4"=>:qt_pyqt4 # PyPlot.backend[1] = "pyqt4" # PyPlot.gui[1] = :qt_pyqt4 # PyPlot.switch_backend("Qt4Agg") - PyPlot.pygui(true) + + # only turn on the gui if we want it + if PyPlot.gui != :none + PyPlot.pygui(true) + end + end catch err warn("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\").") diff --git a/src/recipes.jl b/src/recipes.jl index 8fe1a45c..3aa26a0c 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -118,6 +118,6 @@ end "Sparsity plot... heatmap of non-zero values of a matrix" function spy{T<:Real}(y::AMat{T}; kw...) I,J,V = findnz(y) - heatmap(J, I; leg=false, yflip=true, kw...) + heatmap(J, I; leg=false, yflip=true, nbins=size(y), kw...) end diff --git a/src/utils.jl b/src/utils.jl index a7469163..2bdb6b26 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -206,6 +206,9 @@ function debugplots(on = true) _debugMode.on = on end +debugshow(x) = show(x) +debugshow(x::AbstractArray) = print(summary(x)) + function dumpdict(d::Dict, prefix = "") _debugMode.on || return println() @@ -214,7 +217,8 @@ function dumpdict(d::Dict, prefix = "") end for k in sort(collect(keys(d))) @printf("%14s: ", k) - println(d[k]) + debugshow(d[k]) + println() end println() end