From e60c4633288152a95a8ffcdaf9299cdd8ebf04fe Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Thu, 8 Oct 2015 11:30:20 -0400 Subject: [PATCH] 0.3 support; require Compat; pyplot scatter colormaps --- README.md | 6 ++--- REQUIRE | 3 ++- docs/example_generation.jl | 16 +++++++----- src/Plots.jl | 50 +++++++++++++++++++----------------- src/args.jl | 24 ++++++++--------- src/backends/gadfly.jl | 26 +++++++++---------- src/backends/immerse.jl | 2 +- src/backends/pyplot.jl | 38 ++++++++++++++++----------- src/backends/qwt.jl | 8 +++--- src/backends/unicodeplots.jl | 2 +- src/backends/winston.jl | 10 ++++---- src/colors.jl | 10 +++++--- src/plot.jl | 22 ++++++++-------- src/plotter.jl | 29 +++++++++++---------- src/subplot.jl | 4 +-- src/utils.jl | 16 ++++++------ 16 files changed, 142 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index e5b21449..d154bf4e 100644 --- a/README.md +++ b/README.md @@ -167,9 +167,9 @@ vline!(args...; kw...) = plot!(args...; kw..., linetype = :vline) ohlc(args...; kw...) = plot(args...; kw..., linetype = :ohlc) ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc) -title!(s::AbstractString) = plot!(title = s) -xlabel!(s::AbstractString) = plot!(xlabel = s) -ylabel!(s::AbstractString) = plot!(ylabel = s) +title!(s::@compat(AbstractString)) = plot!(title = s) +xlabel!(s::@compat(AbstractString)) = plot!(xlabel = s) +ylabel!(s::@compat(AbstractString)) = plot!(ylabel = s) xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v) diff --git a/REQUIRE b/REQUIRE index a3780a85..0871e558 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,5 @@ -julia 0.4- +julia 0.3 Colors Reexport +Compat diff --git a/docs/example_generation.jl b/docs/example_generation.jl index 45035686..3bf51c6b 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -3,16 +3,17 @@ module PlotExamples using Plots using Colors +using Compat const DOCDIR = Pkg.dir("Plots") * "/docs" const IMGDIR = Pkg.dir("Plots") * "/img" -doc""" +""" Holds all data needed for a documentation example... header, description, and plotting expression (Expr) """ type PlotExample - header::AbstractString - desc::AbstractString + header::@compat(AbstractString) + desc::@compat(AbstractString) exprs::Vector{Expr} end @@ -171,7 +172,7 @@ end # make and display one plot -function test_example(pkgname::Symbol, idx::Int, debug = true) +function test_examples(pkgname::Symbol, idx::Int; debug = true) Plots._debugMode.on = debug println("Testing plot: $pkgname:$idx:$(examples[idx].header)") backend(pkgname) @@ -183,7 +184,8 @@ function test_example(pkgname::Symbol, idx::Int, debug = true) end # generate all plots and create a dict mapping idx --> plt -function test_all_examples(pkgname::Symbol, debug = false) +function test_examples(pkgname::Symbol; debug = false) + Plots._debugMode.on = debug plts = Dict() for i in 1:length(examples) # if examples[i].header == "Subplots" && !subplotSupported() @@ -191,7 +193,7 @@ function test_all_examples(pkgname::Symbol, debug = false) # end try - plt = test_example(pkgname, i, debug) + plt = test_examples(pkgname, i, debug=debug) plts[i] = plt catch ex # TODO: put error info into markdown? @@ -227,7 +229,7 @@ end -const _ltdesc = Dict( +@compat const _ltdesc = Dict( :none => "No line", :line => "Lines with sorted x-axis", :path => "Lines", diff --git a/src/Plots.jl b/src/Plots.jl index 1f828340..cc0cdee1 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,7 +1,11 @@ -__precompile__() + +if VERSION >= v"0.4-" + __precompile__() +end module Plots +using Compat using Reexport @reexport using Colors @@ -117,34 +121,34 @@ function spy{T<:Real}(y::AMat{T}; kw...) heatmap(J, I; leg=false, yflip=true, kw...) end -title!(s::AbstractString) = plot!(title = s) -xlabel!(s::AbstractString) = plot!(xlabel = s) -ylabel!(s::AbstractString) = plot!(ylabel = s) -xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims) -ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims) +title!(s::@compat(AbstractString)) = plot!(title = s) +xlabel!(s::@compat(AbstractString)) = plot!(xlabel = s) +ylabel!(s::@compat(AbstractString)) = plot!(ylabel = s) +xlims!{T<:Real,S<:Real}(lims::@compat(Tuple{T,S})) = plot!(xlims = lims) +ylims!{T<:Real,S<:Real}(lims::@compat(Tuple{T,S})) = plot!(ylims = lims) xlims!(xmin::Real, xmax::Real) = plot!(xlims = (xmin,xmax)) ylims!(ymin::Real, ymax::Real) = plot!(ylims = (ymin,ymax)) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v) yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v) -xticks!{T<:Real,S<:AbstractString}(ticks::AVec{T}, labels::AVec{S}) = plot!(xticks = (ticks,labels)) -yticks!{T<:Real,S<:AbstractString}(ticks::AVec{T}, labels::AVec{S}) = plot!(yticks = (ticks,labels)) +xticks!{T<:Real,S<:@compat(AbstractString)}(ticks::AVec{T}, labels::AVec{S}) = plot!(xticks = (ticks,labels)) +yticks!{T<:Real,S<:@compat(AbstractString)}(ticks::AVec{T}, labels::AVec{S}) = plot!(yticks = (ticks,labels)) annotate!(anns) = plot!(annotation = anns) xflip!(flip::Bool = true) = plot!(xflip = flip) yflip!(flip::Bool = true) = plot!(yflip = flip) xaxis!(args...) = plot!(xaxis = args) yaxis!(args...) = plot!(yaxis = args) -title!(plt::Plot, s::AbstractString) = plot!(plt; title = s) -xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s) -ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s) -xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; xlims = lims) -ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; ylims = lims) +title!(plt::Plot, s::@compat(AbstractString)) = plot!(plt; title = s) +xlabel!(plt::Plot, s::@compat(AbstractString)) = plot!(plt; xlabel = s) +ylabel!(plt::Plot, s::@compat(AbstractString)) = plot!(plt; ylabel = s) +xlims!{T<:Real,S<:Real}(plt::Plot, lims::@compat(Tuple{T,S})) = plot!(plt; xlims = lims) +ylims!{T<:Real,S<:Real}(plt::Plot, lims::@compat(Tuple{T,S})) = plot!(plt; ylims = lims) xlims!(plt::Plot, xmin::Real, xmax::Real) = plot!(plt; xlims = (xmin,xmax)) ylims!(plt::Plot, ymin::Real, ymax::Real) = plot!(plt; ylims = (ymin,ymax)) xticks!{T<:Real}(plt::Plot, ticks::AVec{T}) = plot!(plt; xticks = ticks) yticks!{T<:Real}(plt::Plot, ticks::AVec{T}) = plot!(plt; yticks = ticks) -xticks!{T<:Real,S<:AbstractString}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; xticks = (ticks,labels)) -yticks!{T<:Real,S<:AbstractString}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; yticks = (ticks,labels)) +xticks!{T<:Real,S<:@compat(AbstractString)}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; xticks = (ticks,labels)) +yticks!{T<:Real,S<:@compat(AbstractString)}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; yticks = (ticks,labels)) annotate!(plt::Plot, anns) = plot!(plt; annotation = anns) xflip!(plt::Plot, flip::Bool = true) = plot!(plt; xflip = flip) yflip!(plt::Plot, flip::Bool = true) = plot!(plt; yflip = flip) @@ -157,20 +161,20 @@ yaxis!(plt::Plot, args...) = plot!(plt; yaxis = args) defaultOutputFormat(plt::PlottingObject) = "png" -function png(plt::PlottingObject, fn::AbstractString) +function png(plt::PlottingObject, fn::@compat(AbstractString)) fn = addExtension(fn, "png") io = open(fn, "w") writemime(io, MIME("image/png"), plt) close(io) end -png(fn::AbstractString) = png(current(), fn) +png(fn::@compat(AbstractString)) = png(current(), fn) -const _savemap = Dict( +@compat const _savemap = Dict( "png" => png, ) -function getExtension(fn::AbstractString) +function getExtension(fn::@compat(AbstractString)) pieces = split(fn, ".") length(pieces) > 1 || error("Can't extract file extension: ", fn) ext = pieces[end] @@ -178,7 +182,7 @@ function getExtension(fn::AbstractString) ext end -function addExtension(fn::AbstractString, ext::AbstractString) +function addExtension(fn::@compat(AbstractString), ext::@compat(AbstractString)) try oldext = getExtension(fn) if oldext == ext @@ -191,7 +195,7 @@ function addExtension(fn::AbstractString, ext::AbstractString) end end -function savefig(plt::PlottingObject, fn::AbstractString) +function savefig(plt::PlottingObject, fn::@compat(AbstractString)) # get the extension local ext @@ -209,11 +213,11 @@ function savefig(plt::PlottingObject, fn::AbstractString) end func(plt, fn) end -savefig(fn::AbstractString) = savefig(current(), fn) +savefig(fn::@compat(AbstractString)) = savefig(current(), fn) # savepng(args...; kw...) = savepng(current(), args...; kw...) -# savepng(plt::PlottingObject, fn::AbstractString; kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io)) +# savepng(plt::PlottingObject, fn::@compat(AbstractString); kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io)) diff --git a/src/args.jl b/src/args.jl index e6192424..73996f7b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1,7 +1,7 @@ const _allAxes = [:auto, :left, :right] -const _axesAliases = Dict( +@compat const _axesAliases = Dict( :a => :auto, :l => :left, :r => :right @@ -9,7 +9,7 @@ const _axesAliases = Dict( const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] -const _typeAliases = Dict( +@compat const _typeAliases = Dict( :n => :none, :no => :none, :l => :line, @@ -29,7 +29,7 @@ const _typeAliases = Dict( ) const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] -const _styleAliases = Dict( +@compat const _styleAliases = Dict( :a => :auto, :s => :solid, :d => :dash, @@ -39,7 +39,7 @@ const _styleAliases = Dict( const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon, :octagon] -const _markerAliases = Dict( +@compat const _markerAliases = Dict( :n => :none, :no => :none, :a => :auto, @@ -74,7 +74,7 @@ const _markerAliases = Dict( ) const _allScales = [:identity, :log, :log2, :log10, :asinh, :sqrt] -const _scaleAliases = Dict( +@compat const _scaleAliases = Dict( :none => :identity, :ln => :log, ) @@ -160,7 +160,7 @@ supportedArgs(::PlottingPackage) = _allArgs supportedArgs() = supportedArgs(backend()) -const _argNotes = Dict( +@compat const _argNotes = Dict( :color => "Series color. To have different marker and/or fill colors, optionally set the markercolor and fillcolor args.", :z => "Determines the depth. For color gradients, we expect 0 ≤ z ≤ 1.", :heatmap_c => "For Qwt heatmaps only... will be deprecated eventually.", @@ -169,7 +169,7 @@ const _argNotes = Dict( # ----------------------------------------------------------------------------- -makeplural(s::Symbol) = Symbol(string(s,"s")) +makeplural(s::Symbol) = symbol(string(s,"s")) autopick(arr::AVec, idx::Integer) = arr[mod1(idx,length(arr))] autopick(notarr, idx::Integer) = notarr @@ -194,7 +194,7 @@ end # Alternate args -const _keyAliases = Dict( +@compat const _keyAliases = Dict( :c => :color, :lab => :label, :l => :line, @@ -308,7 +308,7 @@ end # ----------------------------------------------------------------------------- -wraptuple(x::Tuple) = x +wraptuple(x::@compat(Tuple)) = x wraptuple(x) = (x,) trueOrAllTrue(f::Function, x::AbstractArray) = all(f, x) @@ -332,7 +332,7 @@ end # given one value (:log, or :flip, or (-1,1), etc), set the appropriate arg # TODO: use trueOrAllTrue for subplots which can pass vectors for these -function processAxisArg(d::Dict, axisletter::AbstractString, arg) +function processAxisArg(d::Dict, axisletter::@compat(AbstractString), arg) T = typeof(arg) # if T <: Symbol @@ -345,7 +345,7 @@ function processAxisArg(d::Dict, axisletter::AbstractString, arg) d[symbol(axisletter * "flip")] = true # end - elseif T <: AbstractString + elseif T <: @compat(AbstractString) d[symbol(axisletter * "label")] = arg # xlims/ylims @@ -520,7 +520,7 @@ getArgValue(v, idx) = v # given an argument key (k), we want to extract the argument value for this index. # if nothing is set (or container is empty), return the default. function setDictValue(d::Dict, k::Symbol, idx::Int, defaults::Dict) - if haskey(d, k) && !(typeof(d[k]) <: Union{AbstractArray, Tuple} && isempty(d[k])) + if haskey(d, k) && !(typeof(d[k]) <: @compat(Union{AbstractArray, Tuple}) && isempty(d[k])) d[k] = getArgValue(d[k], idx) else d[k] = defaults[k] diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 77396503..3ac8d9f5 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -80,7 +80,7 @@ function createGadflyPlotObject(d::Dict) # add the legend? if d[:legend] - unshift!(gplt.guides, Gadfly.Guide.manual_color_key("", AbstractString[], Color[])) + unshift!(gplt.guides, Gadfly.Guide.manual_color_key("", @compat(AbstractString)[], Color[])) end gplt.theme = Gadfly.Theme(background_color = getColor(d[:background_color])) @@ -115,9 +115,9 @@ end function getMarkerGeomsAndGuides(d::Dict, initargs::Dict) marker = d[:markershape] if marker == :none && d[:linetype] != :ohlc - return [],[] + return Any[], Any[] end - return [], [createGadflyAnnotation(d, initargs)] + return Any[], [createGadflyAnnotation(d, initargs)] end @@ -144,14 +144,14 @@ Base.first(c::Colorant) = c function addGadflySeries!(gplt, d::Dict, initargs::Dict) - gfargs = [] + gfargs = Any[] # if my PR isn't present, don't set the line_style local extra_theme_args try extra_theme_args = [(:line_style, Gadfly.get_stroke_vector(d[:linestyle]))] catch - extra_theme_args = [] + extra_theme_args = Any[] end # set theme: color, line linewidth, and point size @@ -232,11 +232,11 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict) # nothing special... else - colorgroup = [] + colorgroup = Any[] end # fills/ribbons - yminmax = [] + yminmax = Any[] if d[:fillrange] != nothing fillmin, fillmax = map(makevec, maketuple(d[:fillrange])) nmin, nmax = length(fillmin), length(fillmax) @@ -246,7 +246,7 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict) end # # fillto and ribbon - # yminmax = [] + # yminmax = Any[] # fillto, ribbon = d[:fill], d[:ribbon] # if fillto != nothing @@ -361,7 +361,7 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool) # do we want to add min/max limits for the axis? limsym = isx ? :xlims : :ylims - limargs = [] + limargs = Any[] if haskey(d, limsym) lims = d[limsym] lims == :auto && return @@ -431,7 +431,7 @@ function plot!(::GadflyPackage, plt::Plot; kw...) end -function findGuideAndSet(gplt, t::DataType, s::AbstractString) +function findGuideAndSet(gplt, t::DataType, s::@compat(AbstractString)) for (i,guide) in enumerate(gplt.guides) if isa(guide, t) gplt.guides[i] = t(s) @@ -461,14 +461,14 @@ end # ---------------------------------------------------------------- -function createGadflyAnnotationObject(x, y, val::AbstractString) +function createGadflyAnnotationObject(x, y, val::@compat(AbstractString)) Gadfly.Guide.annotation(Compose.compose( Compose.context(), Compose.text(x, y, val) )) end -function addAnnotations{X,Y,V}(plt::Plot{GadflyPackage}, anns::AVec{Tuple{X,Y,V}}) +function addAnnotations{X,Y,V}(plt::Plot{GadflyPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) for ann in anns push!(plt.o.guides, createGadflyAnnotationObject(ann...)) end @@ -491,7 +491,7 @@ getGadflyContext(::GadflyPackage, subplt::Subplot) = buildGadflySubplotContext(s # create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects function buildGadflySubplotContext(subplt::Subplot) i = 0 - rows = [] + rows = Any[] for rowcnt in subplt.layout.rowcounts push!(rows, Gadfly.hstack([getGadflyContext(plt.backend, plt) for plt in subplt.plts[(1:rowcnt) + i]]...)) i += rowcnt diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index a758f835..06cd64f8 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -53,7 +53,7 @@ end # ---------------------------------------------------------------- -function addAnnotations{X,Y,V}(plt::Plot{ImmersePackage}, anns::AVec{Tuple{X,Y,V}}) +function addAnnotations{X,Y,V}(plt::Plot{ImmersePackage}, anns::AVec{@compat(Tuple{X,Y,V})}) for ann in anns push!(plt.o[2].guides, createGadflyAnnotationObject(ann...)) end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index bc02c0ff..f2f86632 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -55,7 +55,7 @@ supportedArgs(::PyPlotPackage) = [ :yscale, :xflip, :yflip, - # :z, + :z, ] supportedAxes(::PyPlotPackage) = _allAxes supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline] @@ -68,6 +68,11 @@ subplotSupported(::PyPlotPackage) = false getPyPlotColor(c::Colorant) = map(f->float(f(c)), (red, green, blue, alpha)) getPyPlotColor(scheme::ColorScheme) = getPyPlotColor(getColor(scheme)) +# getPyPlotColorMap(c::ColorGradient) = PyPlot.matplotlib[:colors][:ListedColormap](map(getPyPlotColor, getColorVector(c))) +function getPyPlotColorMap(c::ColorGradient) + pycolors.pymember("LinearSegmentedColormap")[:from_list]("tmp", map(getPyPlotColor, getColorVector(c))) +end + # get the style (solid, dashed, etc) function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol) linetype == :none && return " " @@ -97,7 +102,7 @@ function getPyPlotMarker(marker::Symbol) end # pass through -function getPyPlotMarker(marker::AbstractString) +function getPyPlotMarker(marker::@compat(AbstractString)) @assert length(marker) == 1 marker end @@ -119,26 +124,26 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol) if axis == :right ax = getRightAxis(plt.o[1]) ax[:set_ylabel](plt.initargs[:yrightlabel]) - fmap = Dict( + fmap = @compat Dict( :hist => :hist, :sticks => :bar, :bar => :bar, :heatmap => :hexbin, :hexbin => :hexbin, - # :scatter => :scatter + :scatter => :scatter ) return ax[get(fmap, linetype, :plot)] # return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))] end # get the function - fmap = Dict( + fmap = @compat Dict( :hist => PyPlot.plt[:hist], :sticks => PyPlot.bar, :bar => PyPlot.bar, :heatmap => PyPlot.hexbin, :hexbin => PyPlot.hexbin, - # :scatter => PyPlot.scatter + :scatter => PyPlot.scatter ) return get(fmap, linetype, PyPlot.plot) # return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot)) @@ -208,7 +213,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...) d,_ = sticksHack(;d...) elseif lt == :scatter - d[:linetype] = :none + # d[:linetype] = :none if d[:markershape] == :none d[:markershape] = :ellipse end @@ -251,11 +256,14 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...) extraargs[:marker] = getPyPlotMarker(d[:markershape]) if lt == :scatter - extraargs[:s] = d[:markersize] - extraargs[:c] = getPyPlotColor(d[:markercolor]) - extraargs[:linewidths] = d[:linewidth] - if haskey(d, :colorscheme) - extraargs[:cmap] = d[:colorscheme] + extraargs[:s] = d[:markersize]^2 + #extraargs[:linewidths] = d[:linewidth] + c = d[:markercolor] + if isa(c, ColorGradient) && d[:z] != nothing + extraargs[:c] = convert(Vector{Float64}, d[:z]) + extraargs[:cmap] = getPyPlotColorMap(c) + else + extraargs[:c] = getPyPlotColor(c) end else extraargs[:markersize] = d[:markersize] @@ -286,7 +294,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...) fillrange = d[:fillrange] if fillrange != nothing fillcolor = getPyPlotColor(d[:fillcolor]) - if typeof(fillrange) <: Union{Real, AVec} + if typeof(fillrange) <: @compat(Union{Real, AVec}) ax[:fill_between](d[:x], fillrange, d[:y], facecolor = fillcolor) else ax[:fill_between](d[:x], fillrange..., facecolor = fillcolor) @@ -368,12 +376,12 @@ end # ----------------------------------------------------------------- -function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::AbstractString) +function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::@compat(AbstractString)) ax = getLeftAxis(plt.o[1]) ax[:annotate](val, xy = (x,y)) end -function addAnnotations{X,Y,V}(plt::Plot{PyPlotPackage}, anns::AVec{Tuple{X,Y,V}}) +function addAnnotations{X,Y,V}(plt::Plot{PyPlotPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) for ann in anns createPyPlotAnnotationObject(plt, ann...) end diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index efe7b172..cf2d974d 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -61,7 +61,7 @@ supportedScales(::QwtPackage) = [:identity, :log10] # ------------------------------- -const _qwtAliases = Dict( +@compat const _qwtAliases = Dict( :nbins => :heatmap_n, :fillrange => :fillto, :linewidth => :width, @@ -210,14 +210,14 @@ function addLineMarker(plt::Plot{QwtPackage}, d::Dict) # marker[:attach](plt.o.widget) end -function createQwtAnnotation(plt::Plot, x, y, val::AbstractString) +function createQwtAnnotation(plt::Plot, x, y, val::@compat(AbstractString)) marker = Qwt.QWT.QwtPlotMarker() marker[:setValue](x, y) marker[:setLabel](Qwt.QWT.QwtText(val)) marker[:attach](plt.o.widget) end -function addAnnotations{X,Y,V}(plt::Plot{QwtPackage}, anns::AVec{Tuple{X,Y,V}}) +function addAnnotations{X,Y,V}(plt::Plot{QwtPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) for ann in anns createQwtAnnotation(plt, ann...) end @@ -241,7 +241,7 @@ end # ------------------------------- -# savepng(::QwtPackage, plt::PlottingObject, fn::AbstractString, args...) = Qwt.savepng(plt.o, fn) +# savepng(::QwtPackage, plt::PlottingObject, fn::@compat(AbstractString), args...) = Qwt.savepng(plt.o, fn) # ------------------------------- diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 48ab8ffe..67395528 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -212,7 +212,7 @@ end # ------------------------------- -# function savepng(::UnicodePlotsPackage, plt::PlottingObject, fn::AbstractString, args...) +# function savepng(::UnicodePlotsPackage, plt::PlottingObject, fn::@compat(AbstractString), args...) function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{UnicodePlotsPackage}) # make some whitespace and show the plot diff --git a/src/backends/winston.jl b/src/backends/winston.jl index c15f290b..faf15fc6 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -12,13 +12,13 @@ winston() = backend(:winston) ## dictionaries for conversion of Plots.jl names to Winston ones. -const winston_linestyle = Dict(:solid=>"solid", +@compat const winston_linestyle = Dict(:solid=>"solid", :dash=>"dash", :dot=>"dotted", :dashdot=>"dotdashed" ) -const winston_marker = Dict(:none=>".", +@compat const winston_marker = Dict(:none=>".", :rect => "square", :ellipse=>"circle", :diamond=>"diamond", @@ -215,7 +215,7 @@ end # ---------------------------------------------------------------- -const _winstonNames = Dict( +@compat const _winstonNames = Dict( :xlims => :xrange, :ylims => :yrange, :xscale => :xlog, @@ -243,11 +243,11 @@ end # ---------------------------------------------------------------- -function createWinstonAnnotationObject(plt::Plot{WinstonPackage}, x, y, val::AbstractString) +function createWinstonAnnotationObject(plt::Plot{WinstonPackage}, x, y, val::@compat(AbstractString)) Winston.text(x, y, val) end -function addAnnotations{X,Y,V}(plt::Plot{WinstonPackage}, anns::AVec{Tuple{X,Y,V}}) +function addAnnotations{X,Y,V}(plt::Plot{WinstonPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) for ann in anns createWinstonAnnotationObject(plt, ann...) end diff --git a/src/colors.jl b/src/colors.jl index e50af8ec..6ba17fe1 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -83,7 +83,7 @@ end # -------------------------------------------------------------- -convertColor(c::Union{AbstractString, Symbol}) = parse(Colorant, string(c)) +convertColor(c::@compat(Union{AbstractString, Symbol})) = parse(Colorant, string(c)) convertColor(c::Colorant) = c convertColor(cvec::AbstractVector) = map(convertColor, cvec) @@ -92,8 +92,6 @@ convertColor(cvec::AbstractVector) = map(convertColor, cvec) abstract ColorScheme getColor(scheme::ColorScheme) = getColor(scheme, 1) -# getColor(scheme::ColorScheme, idx::Integer) = getColor(scheme, 0.0, idx) -# getColorZ(scheme::ColorScheme, z::AbstractFloat) = getColor(scheme, z, 0) getColorVector(scheme::ColorScheme) = [getColor(scheme)] colorscheme(scheme::ColorScheme) = scheme @@ -108,7 +106,7 @@ colorscheme(c::Colorant) = ColorWrapper(c) const _rainbowColors = [colorant"blue", colorant"purple", colorant"green", colorant"orange", colorant"red"] -const _gradients = Dict( +@compat const _gradients = Dict( :blues => [colorant"lightblue", colorant"darkblue"], :reds => [colorant"lightpink", colorant"darkred"], :greens => [colorant"lightgreen", colorant"darkgreen"], @@ -182,6 +180,10 @@ getColorVector(gradient::ColorGradient) = gradient.colors # RGB(Lab(l, a, b)) # end +# for 0.3 +Colors.RGBA(c::Colorant) = RGBA(red(c), green(c), blue(c), alpha(c)) +Colors.RGB(c::Colorant) = RGB(red(c), green(c), blue(c)) + function interpolate_rgb(c1::Colorant, c2::Colorant, w::Real) rgb1 = RGBA(c1) rgb2 = RGBA(c2) diff --git a/src/plot.jl b/src/plot.jl index 277562c0..5f3a61e2 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -28,7 +28,7 @@ convertSeriesIndex(plt::Plot, n::Int) = n # --------------------------------------------------------- -doc""" +""" The main plot command. Use `plot` to create a new plot object, and `plot!` to add to an existing one: ``` @@ -146,7 +146,7 @@ function setTicksFromStringVector(d::Dict, di::Dict, sym::Symbol, ticksym::Symbo T = eltype(v) # @show T - if T <: AbstractString || (!isempty(T.types) && all(x -> x <: AbstractString, T.types)) + if T <: @compat(AbstractString) || (!isempty(T.types) && all(x -> x <: @compat(AbstractString), T.types)) # @show sym ticksym di[sym] ticks = unique(di[sym]) @@ -177,9 +177,9 @@ updateDictWithMeta(d::Dict, initargs::Dict, meta, isx::Bool) = nothing # -------------------------------------------------------------------- -annotations(::Void) = [] -annotations{X<:Real, Y<:Real, V}(v::AVec{Tuple{X,Y,V}}) = v -annotations{X<:Real, Y<:Real, V}(t::Tuple{X,Y,V}) = [t] +annotations(::@compat(Void)) = [] +annotations{X<:Real, Y<:Real, V}(v::AVec{@compat(Tuple{X,Y,V})}) = v +annotations{X<:Real, Y<:Real, V}(t::@compat(Tuple{X,Y,V})) = [t] annotations(anns) = error("Expecting a tuple (or vector of tuples) for annotations: ", "(x, y, annotation)\n got: $(typeof(anns))") @@ -200,10 +200,10 @@ end # This should cut down on boilerplate code and allow more focused dispatch on type # note: returns meta information... mainly for use with automatic labeling from DataFrames for now -typealias FuncOrFuncs Union{Function, AVec{Function}} +typealias FuncOrFuncs @compat(Union{Function, AVec{Function}}) # missing -convertToAnyVector(v::Void; kw...) = Any[nothing], nothing +convertToAnyVector(v::@compat(Void); kw...) = Any[nothing], nothing # fixed number of blank series convertToAnyVector(n::Integer; kw...) = Any[zero(0) for i in 1:n], nothing @@ -212,7 +212,7 @@ convertToAnyVector(n::Integer; kw...) = Any[zero(0) for i in 1:n], nothing convertToAnyVector{T<:Real}(v::AVec{T}; kw...) = Any[v], nothing # string vector -convertToAnyVector{T<:AbstractString}(v::AVec{T}; kw...) = Any[v], nothing +convertToAnyVector{T<:@compat(AbstractString)}(v::AVec{T}; kw...) = Any[v], nothing # numeric matrix convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2)], nothing @@ -231,7 +231,7 @@ convertToAnyVector(v::AVec; kw...) = Any[vi for vi in v], nothing # in computeXandY, we take in any of the possible items, convert into proper x/y vectors, then return. # this is also where all the "set x to 1:length(y)" happens, and also where we assert on lengths. -computeX(x::Void, y) = 1:length(y) +computeX(x::@compat(Void), y) = 1:length(y) computeX(x, y) = copy(x) computeY(x, y::Function) = map(y, x) computeY(x, y) = copy(y) @@ -254,7 +254,7 @@ function createKWargsList(plt::PlottingObject, x, y; kw...) ys, ymeta = convertToAnyVector(y; kw...) mx = length(xs) my = length(ys) - ret = [] + ret = Any[] for i in 1:max(mx, my) # try to set labels using ymeta @@ -297,7 +297,7 @@ end # handle grouping function createKWargsList(plt::PlottingObject, groupby::GroupBy, args...; kw...) - ret = [] + ret = Any[] for (i,glab) in enumerate(groupby.groupLabels) # TODO: don't automatically overwrite labels kwlist, xmeta, ymeta = createKWargsList(plt, args...; kw..., diff --git a/src/plotter.jl b/src/plotter.jl index e700e8d7..7337c86c 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -87,7 +87,7 @@ end # --------------------------------------------------------- -doc""" +""" Returns the current plotting package name. Initializes package on first call. """ function backend() @@ -101,51 +101,52 @@ function backend() try @eval import Qwt @eval export Qwt - catch - error("Couldn't import Qwt. Install it with: Pkg.clone(\"https://github.com/tbreloff/Qwt.jl.git\")\n (Note: also requires pyqt and pyqwt)") + catch err + error("Couldn't import Qwt. Install it with: Pkg.clone(\"https://github.com/tbreloff/Qwt.jl.git\")\n (Note: also requires pyqt and pyqwt).\n Error: ", err) end elseif currentBackendSymbol == :gadfly try @eval import Gadfly, Compose @eval export Gadfly, Compose - catch - error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\")") + catch err + error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\").\n Error: ", err) end elseif currentBackendSymbol == :unicodeplots try @eval import UnicodePlots @eval export UnicodePlots - catch - error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\")") + catch err + error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\").\n Error: ", err) end elseif currentBackendSymbol == :pyplot try @eval import PyPlot @eval export PyPlot + @eval const pycolors = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colors")) if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay) PyPlot.ioff() end - catch - error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\")") + catch err + error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\").\n Error: ", err) end elseif currentBackendSymbol == :immerse try @eval import Immerse, Gadfly, Compose, Gtk @eval export Immerse, Gadfly, Compose, Gtk - catch - error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\")") + catch err + error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\").\n Error: ", err) end elseif currentBackendSymbol == :winston try @eval import Winston, Gtk @eval export Winston, Gtk - catch - error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\")") + catch err + error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\").\n Error: ", err) end else @@ -158,7 +159,7 @@ function backend() CURRENT_BACKEND.pkg end -doc""" +""" Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots """ function backend(modname) diff --git a/src/subplot.jl b/src/subplot.jl index 417f2840..b766ba92 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -53,7 +53,7 @@ function validateSubplotSupported() end end -doc""" +""" Create a series of plots: ``` y = rand(100,3) @@ -102,7 +102,7 @@ function subplot(args...; kw...) subplt end -doc""" +""" Adds to a subplot. """ diff --git a/src/utils.jl b/src/utils.jl index 94ac5ecf..a3559cf6 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,7 +1,7 @@ calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for i in 1:length(edges)-1] -doc"Make histogram-like bins of data" +"Make histogram-like bins of data" function binData(data, nbins) lo, hi = extrema(data) edges = collect(linspace(lo, hi, nbins+1)) @@ -14,7 +14,7 @@ function binData(data, nbins) edges, midpoints, buckets, counts end -doc""" +""" A hacky replacement for a histogram when the backend doesn't support histograms directly. Convert it into a bar chart with the appropriate x/y values. """ @@ -30,7 +30,7 @@ function histogramHack(; kw...) d end -doc""" +""" A hacky replacement for a bar graph when the backend doesn't support bars directly. Convert it into a line chart with fillrange set. """ @@ -70,7 +70,7 @@ function barHack(; kw...) end -doc""" +""" A hacky replacement for a sticks graph when the backend doesn't support sticks directly. Convert it into a line chart that traces the sticks, and a scatter that sets markers at the points. """ @@ -111,7 +111,7 @@ makevec{T}(v::T) = T[v] "duplicate a single value, or pass the 2-tuple through" maketuple(x::Real) = (x,x) -maketuple{T,S}(x::Tuple{T,S}) = x +maketuple{T,S}(x::@compat(Tuple{T,S})) = x function replaceAliases!(d::Dict, aliases::Dict) @@ -137,12 +137,12 @@ function regressionXY(x, y) regx, regy end -# ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits +# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits ticksType{T<:Real}(ticks::AVec{T}) = :ticks -ticksType{T<:AVec,S<:AVec}(ticks::Tuple{T,S}) = :ticks_and_labels +ticksType{T<:AVec,S<:AVec}(ticks::@compat(Tuple{T,S})) = :ticks_and_labels ticksType(ticks) = :invalid -limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits +limsType{T<:Real,S<:Real}(lims::@compat(Tuple{T,S})) = :limits limsType(lims) = :invalid