0.3 support; require Compat; pyplot scatter colormaps
This commit is contained in:
parent
537d74196b
commit
e60c463328
@ -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)
|
||||||
ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc)
|
ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc)
|
||||||
|
|
||||||
title!(s::AbstractString) = plot!(title = s)
|
title!(s::@compat(AbstractString)) = plot!(title = s)
|
||||||
xlabel!(s::AbstractString) = plot!(xlabel = s)
|
xlabel!(s::@compat(AbstractString)) = plot!(xlabel = s)
|
||||||
ylabel!(s::AbstractString) = plot!(ylabel = s)
|
ylabel!(s::@compat(AbstractString)) = plot!(ylabel = s)
|
||||||
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
|
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
|
||||||
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
|
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
|
||||||
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
|
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
|
||||||
|
|||||||
@ -3,16 +3,17 @@ module PlotExamples
|
|||||||
|
|
||||||
using Plots
|
using Plots
|
||||||
using Colors
|
using Colors
|
||||||
|
using Compat
|
||||||
|
|
||||||
const DOCDIR = Pkg.dir("Plots") * "/docs"
|
const DOCDIR = Pkg.dir("Plots") * "/docs"
|
||||||
const IMGDIR = Pkg.dir("Plots") * "/img"
|
const IMGDIR = Pkg.dir("Plots") * "/img"
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
Holds all data needed for a documentation example... header, description, and plotting expression (Expr)
|
Holds all data needed for a documentation example... header, description, and plotting expression (Expr)
|
||||||
"""
|
"""
|
||||||
type PlotExample
|
type PlotExample
|
||||||
header::AbstractString
|
header::@compat(AbstractString)
|
||||||
desc::AbstractString
|
desc::@compat(AbstractString)
|
||||||
exprs::Vector{Expr}
|
exprs::Vector{Expr}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -171,7 +172,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# make and display one plot
|
# 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
|
Plots._debugMode.on = debug
|
||||||
println("Testing plot: $pkgname:$idx:$(examples[idx].header)")
|
println("Testing plot: $pkgname:$idx:$(examples[idx].header)")
|
||||||
backend(pkgname)
|
backend(pkgname)
|
||||||
@ -183,7 +184,8 @@ function test_example(pkgname::Symbol, idx::Int, debug = true)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# generate all plots and create a dict mapping idx --> plt
|
# 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()
|
plts = Dict()
|
||||||
for i in 1:length(examples)
|
for i in 1:length(examples)
|
||||||
# if examples[i].header == "Subplots" && !subplotSupported()
|
# if examples[i].header == "Subplots" && !subplotSupported()
|
||||||
@ -191,7 +193,7 @@ function test_all_examples(pkgname::Symbol, debug = false)
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
try
|
try
|
||||||
plt = test_example(pkgname, i, debug)
|
plt = test_examples(pkgname, i, debug=debug)
|
||||||
plts[i] = plt
|
plts[i] = plt
|
||||||
catch ex
|
catch ex
|
||||||
# TODO: put error info into markdown?
|
# TODO: put error info into markdown?
|
||||||
@ -227,7 +229,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const _ltdesc = Dict(
|
@compat const _ltdesc = Dict(
|
||||||
:none => "No line",
|
:none => "No line",
|
||||||
:line => "Lines with sorted x-axis",
|
:line => "Lines with sorted x-axis",
|
||||||
:path => "Lines",
|
:path => "Lines",
|
||||||
|
|||||||
50
src/Plots.jl
50
src/Plots.jl
@ -1,7 +1,11 @@
|
|||||||
__precompile__()
|
|
||||||
|
if VERSION >= v"0.4-"
|
||||||
|
__precompile__()
|
||||||
|
end
|
||||||
|
|
||||||
module Plots
|
module Plots
|
||||||
|
|
||||||
|
using Compat
|
||||||
using Reexport
|
using Reexport
|
||||||
@reexport using Colors
|
@reexport using Colors
|
||||||
|
|
||||||
@ -117,34 +121,34 @@ function spy{T<:Real}(y::AMat{T}; kw...)
|
|||||||
heatmap(J, I; leg=false, yflip=true, kw...)
|
heatmap(J, I; leg=false, yflip=true, kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
title!(s::AbstractString) = plot!(title = s)
|
title!(s::@compat(AbstractString)) = plot!(title = s)
|
||||||
xlabel!(s::AbstractString) = plot!(xlabel = s)
|
xlabel!(s::@compat(AbstractString)) = plot!(xlabel = s)
|
||||||
ylabel!(s::AbstractString) = plot!(ylabel = s)
|
ylabel!(s::@compat(AbstractString)) = plot!(ylabel = s)
|
||||||
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
|
xlims!{T<:Real,S<:Real}(lims::@compat(Tuple{T,S})) = plot!(xlims = lims)
|
||||||
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
|
ylims!{T<:Real,S<:Real}(lims::@compat(Tuple{T,S})) = plot!(ylims = lims)
|
||||||
xlims!(xmin::Real, xmax::Real) = plot!(xlims = (xmin,xmax))
|
xlims!(xmin::Real, xmax::Real) = plot!(xlims = (xmin,xmax))
|
||||||
ylims!(ymin::Real, ymax::Real) = plot!(ylims = (ymin,ymax))
|
ylims!(ymin::Real, ymax::Real) = plot!(ylims = (ymin,ymax))
|
||||||
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
|
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
|
||||||
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = 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))
|
xticks!{T<:Real,S<:@compat(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))
|
yticks!{T<:Real,S<:@compat(AbstractString)}(ticks::AVec{T}, labels::AVec{S}) = plot!(yticks = (ticks,labels))
|
||||||
annotate!(anns) = plot!(annotation = anns)
|
annotate!(anns) = plot!(annotation = anns)
|
||||||
xflip!(flip::Bool = true) = plot!(xflip = flip)
|
xflip!(flip::Bool = true) = plot!(xflip = flip)
|
||||||
yflip!(flip::Bool = true) = plot!(yflip = flip)
|
yflip!(flip::Bool = true) = plot!(yflip = flip)
|
||||||
xaxis!(args...) = plot!(xaxis = args)
|
xaxis!(args...) = plot!(xaxis = args)
|
||||||
yaxis!(args...) = plot!(yaxis = args)
|
yaxis!(args...) = plot!(yaxis = args)
|
||||||
|
|
||||||
title!(plt::Plot, s::AbstractString) = plot!(plt; title = s)
|
title!(plt::Plot, s::@compat(AbstractString)) = plot!(plt; title = s)
|
||||||
xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s)
|
xlabel!(plt::Plot, s::@compat(AbstractString)) = plot!(plt; xlabel = s)
|
||||||
ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s)
|
ylabel!(plt::Plot, s::@compat(AbstractString)) = plot!(plt; ylabel = s)
|
||||||
xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; xlims = lims)
|
xlims!{T<:Real,S<:Real}(plt::Plot, lims::@compat(Tuple{T,S})) = plot!(plt; xlims = lims)
|
||||||
ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; ylims = 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))
|
xlims!(plt::Plot, xmin::Real, xmax::Real) = plot!(plt; xlims = (xmin,xmax))
|
||||||
ylims!(plt::Plot, ymin::Real, ymax::Real) = plot!(plt; ylims = (ymin,ymax))
|
ylims!(plt::Plot, ymin::Real, ymax::Real) = plot!(plt; ylims = (ymin,ymax))
|
||||||
xticks!{T<:Real}(plt::Plot, ticks::AVec{T}) = plot!(plt; xticks = ticks)
|
xticks!{T<:Real}(plt::Plot, ticks::AVec{T}) = plot!(plt; xticks = ticks)
|
||||||
yticks!{T<:Real}(plt::Plot, ticks::AVec{T}) = plot!(plt; yticks = 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))
|
xticks!{T<:Real,S<:@compat(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))
|
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)
|
annotate!(plt::Plot, anns) = plot!(plt; annotation = anns)
|
||||||
xflip!(plt::Plot, flip::Bool = true) = plot!(plt; xflip = flip)
|
xflip!(plt::Plot, flip::Bool = true) = plot!(plt; xflip = flip)
|
||||||
yflip!(plt::Plot, flip::Bool = true) = plot!(plt; yflip = 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"
|
defaultOutputFormat(plt::PlottingObject) = "png"
|
||||||
|
|
||||||
function png(plt::PlottingObject, fn::AbstractString)
|
function png(plt::PlottingObject, fn::@compat(AbstractString))
|
||||||
fn = addExtension(fn, "png")
|
fn = addExtension(fn, "png")
|
||||||
io = open(fn, "w")
|
io = open(fn, "w")
|
||||||
writemime(io, MIME("image/png"), plt)
|
writemime(io, MIME("image/png"), plt)
|
||||||
close(io)
|
close(io)
|
||||||
end
|
end
|
||||||
png(fn::AbstractString) = png(current(), fn)
|
png(fn::@compat(AbstractString)) = png(current(), fn)
|
||||||
|
|
||||||
|
|
||||||
const _savemap = Dict(
|
@compat const _savemap = Dict(
|
||||||
"png" => png,
|
"png" => png,
|
||||||
)
|
)
|
||||||
|
|
||||||
function getExtension(fn::AbstractString)
|
function getExtension(fn::@compat(AbstractString))
|
||||||
pieces = split(fn, ".")
|
pieces = split(fn, ".")
|
||||||
length(pieces) > 1 || error("Can't extract file extension: ", fn)
|
length(pieces) > 1 || error("Can't extract file extension: ", fn)
|
||||||
ext = pieces[end]
|
ext = pieces[end]
|
||||||
@ -178,7 +182,7 @@ function getExtension(fn::AbstractString)
|
|||||||
ext
|
ext
|
||||||
end
|
end
|
||||||
|
|
||||||
function addExtension(fn::AbstractString, ext::AbstractString)
|
function addExtension(fn::@compat(AbstractString), ext::@compat(AbstractString))
|
||||||
try
|
try
|
||||||
oldext = getExtension(fn)
|
oldext = getExtension(fn)
|
||||||
if oldext == ext
|
if oldext == ext
|
||||||
@ -191,7 +195,7 @@ function addExtension(fn::AbstractString, ext::AbstractString)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function savefig(plt::PlottingObject, fn::AbstractString)
|
function savefig(plt::PlottingObject, fn::@compat(AbstractString))
|
||||||
|
|
||||||
# get the extension
|
# get the extension
|
||||||
local ext
|
local ext
|
||||||
@ -209,11 +213,11 @@ function savefig(plt::PlottingObject, fn::AbstractString)
|
|||||||
end
|
end
|
||||||
func(plt, fn)
|
func(plt, fn)
|
||||||
end
|
end
|
||||||
savefig(fn::AbstractString) = savefig(current(), fn)
|
savefig(fn::@compat(AbstractString)) = savefig(current(), fn)
|
||||||
|
|
||||||
|
|
||||||
# savepng(args...; kw...) = savepng(current(), args...; kw...)
|
# 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))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
24
src/args.jl
24
src/args.jl
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
const _allAxes = [:auto, :left, :right]
|
const _allAxes = [:auto, :left, :right]
|
||||||
const _axesAliases = Dict(
|
@compat const _axesAliases = Dict(
|
||||||
:a => :auto,
|
:a => :auto,
|
||||||
:l => :left,
|
:l => :left,
|
||||||
:r => :right
|
:r => :right
|
||||||
@ -9,7 +9,7 @@ const _axesAliases = Dict(
|
|||||||
|
|
||||||
const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
|
const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
|
||||||
:heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
|
:heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
|
||||||
const _typeAliases = Dict(
|
@compat const _typeAliases = Dict(
|
||||||
:n => :none,
|
:n => :none,
|
||||||
:no => :none,
|
:no => :none,
|
||||||
:l => :line,
|
:l => :line,
|
||||||
@ -29,7 +29,7 @@ const _typeAliases = Dict(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
const _styleAliases = Dict(
|
@compat const _styleAliases = Dict(
|
||||||
:a => :auto,
|
:a => :auto,
|
||||||
:s => :solid,
|
:s => :solid,
|
||||||
:d => :dash,
|
:d => :dash,
|
||||||
@ -39,7 +39,7 @@ const _styleAliases = Dict(
|
|||||||
|
|
||||||
const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle,
|
const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle,
|
||||||
:cross, :xcross, :star1, :star2, :hexagon, :octagon]
|
:cross, :xcross, :star1, :star2, :hexagon, :octagon]
|
||||||
const _markerAliases = Dict(
|
@compat const _markerAliases = Dict(
|
||||||
:n => :none,
|
:n => :none,
|
||||||
:no => :none,
|
:no => :none,
|
||||||
:a => :auto,
|
:a => :auto,
|
||||||
@ -74,7 +74,7 @@ const _markerAliases = Dict(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const _allScales = [:identity, :log, :log2, :log10, :asinh, :sqrt]
|
const _allScales = [:identity, :log, :log2, :log10, :asinh, :sqrt]
|
||||||
const _scaleAliases = Dict(
|
@compat const _scaleAliases = Dict(
|
||||||
:none => :identity,
|
:none => :identity,
|
||||||
:ln => :log,
|
:ln => :log,
|
||||||
)
|
)
|
||||||
@ -160,7 +160,7 @@ supportedArgs(::PlottingPackage) = _allArgs
|
|||||||
supportedArgs() = supportedArgs(backend())
|
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.",
|
: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.",
|
:z => "Determines the depth. For color gradients, we expect 0 ≤ z ≤ 1.",
|
||||||
:heatmap_c => "For Qwt heatmaps only... will be deprecated eventually.",
|
: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(arr::AVec, idx::Integer) = arr[mod1(idx,length(arr))]
|
||||||
autopick(notarr, idx::Integer) = notarr
|
autopick(notarr, idx::Integer) = notarr
|
||||||
@ -194,7 +194,7 @@ end
|
|||||||
|
|
||||||
# Alternate args
|
# Alternate args
|
||||||
|
|
||||||
const _keyAliases = Dict(
|
@compat const _keyAliases = Dict(
|
||||||
:c => :color,
|
:c => :color,
|
||||||
:lab => :label,
|
:lab => :label,
|
||||||
:l => :line,
|
:l => :line,
|
||||||
@ -308,7 +308,7 @@ end
|
|||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
wraptuple(x::Tuple) = x
|
wraptuple(x::@compat(Tuple)) = x
|
||||||
wraptuple(x) = (x,)
|
wraptuple(x) = (x,)
|
||||||
|
|
||||||
trueOrAllTrue(f::Function, x::AbstractArray) = all(f, 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
|
# 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
|
# 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)
|
T = typeof(arg)
|
||||||
# if T <: Symbol
|
# if T <: Symbol
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ function processAxisArg(d::Dict, axisletter::AbstractString, arg)
|
|||||||
d[symbol(axisletter * "flip")] = true
|
d[symbol(axisletter * "flip")] = true
|
||||||
# end
|
# end
|
||||||
|
|
||||||
elseif T <: AbstractString
|
elseif T <: @compat(AbstractString)
|
||||||
d[symbol(axisletter * "label")] = arg
|
d[symbol(axisletter * "label")] = arg
|
||||||
|
|
||||||
# xlims/ylims
|
# 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.
|
# 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.
|
# if nothing is set (or container is empty), return the default.
|
||||||
function setDictValue(d::Dict, k::Symbol, idx::Int, defaults::Dict)
|
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)
|
d[k] = getArgValue(d[k], idx)
|
||||||
else
|
else
|
||||||
d[k] = defaults[k]
|
d[k] = defaults[k]
|
||||||
|
|||||||
@ -80,7 +80,7 @@ function createGadflyPlotObject(d::Dict)
|
|||||||
|
|
||||||
# add the legend?
|
# add the legend?
|
||||||
if d[: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
|
end
|
||||||
|
|
||||||
gplt.theme = Gadfly.Theme(background_color = getColor(d[:background_color]))
|
gplt.theme = Gadfly.Theme(background_color = getColor(d[:background_color]))
|
||||||
@ -115,9 +115,9 @@ end
|
|||||||
function getMarkerGeomsAndGuides(d::Dict, initargs::Dict)
|
function getMarkerGeomsAndGuides(d::Dict, initargs::Dict)
|
||||||
marker = d[:markershape]
|
marker = d[:markershape]
|
||||||
if marker == :none && d[:linetype] != :ohlc
|
if marker == :none && d[:linetype] != :ohlc
|
||||||
return [],[]
|
return Any[], Any[]
|
||||||
end
|
end
|
||||||
return [], [createGadflyAnnotation(d, initargs)]
|
return Any[], [createGadflyAnnotation(d, initargs)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -144,14 +144,14 @@ Base.first(c::Colorant) = c
|
|||||||
|
|
||||||
function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
||||||
|
|
||||||
gfargs = []
|
gfargs = Any[]
|
||||||
|
|
||||||
# if my PR isn't present, don't set the line_style
|
# if my PR isn't present, don't set the line_style
|
||||||
local extra_theme_args
|
local extra_theme_args
|
||||||
try
|
try
|
||||||
extra_theme_args = [(:line_style, Gadfly.get_stroke_vector(d[:linestyle]))]
|
extra_theme_args = [(:line_style, Gadfly.get_stroke_vector(d[:linestyle]))]
|
||||||
catch
|
catch
|
||||||
extra_theme_args = []
|
extra_theme_args = Any[]
|
||||||
end
|
end
|
||||||
|
|
||||||
# set theme: color, line linewidth, and point size
|
# set theme: color, line linewidth, and point size
|
||||||
@ -232,11 +232,11 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
|||||||
|
|
||||||
# nothing special...
|
# nothing special...
|
||||||
else
|
else
|
||||||
colorgroup = []
|
colorgroup = Any[]
|
||||||
end
|
end
|
||||||
|
|
||||||
# fills/ribbons
|
# fills/ribbons
|
||||||
yminmax = []
|
yminmax = Any[]
|
||||||
if d[:fillrange] != nothing
|
if d[:fillrange] != nothing
|
||||||
fillmin, fillmax = map(makevec, maketuple(d[:fillrange]))
|
fillmin, fillmax = map(makevec, maketuple(d[:fillrange]))
|
||||||
nmin, nmax = length(fillmin), length(fillmax)
|
nmin, nmax = length(fillmin), length(fillmax)
|
||||||
@ -246,7 +246,7 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# # fillto and ribbon
|
# # fillto and ribbon
|
||||||
# yminmax = []
|
# yminmax = Any[]
|
||||||
# fillto, ribbon = d[:fill], d[:ribbon]
|
# fillto, ribbon = d[:fill], d[:ribbon]
|
||||||
|
|
||||||
# if fillto != nothing
|
# 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?
|
# do we want to add min/max limits for the axis?
|
||||||
limsym = isx ? :xlims : :ylims
|
limsym = isx ? :xlims : :ylims
|
||||||
limargs = []
|
limargs = Any[]
|
||||||
if haskey(d, limsym)
|
if haskey(d, limsym)
|
||||||
lims = d[limsym]
|
lims = d[limsym]
|
||||||
lims == :auto && return
|
lims == :auto && return
|
||||||
@ -431,7 +431,7 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function findGuideAndSet(gplt, t::DataType, s::AbstractString)
|
function findGuideAndSet(gplt, t::DataType, s::@compat(AbstractString))
|
||||||
for (i,guide) in enumerate(gplt.guides)
|
for (i,guide) in enumerate(gplt.guides)
|
||||||
if isa(guide, t)
|
if isa(guide, t)
|
||||||
gplt.guides[i] = t(s)
|
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(
|
Gadfly.Guide.annotation(Compose.compose(
|
||||||
Compose.context(),
|
Compose.context(),
|
||||||
Compose.text(x, y, val)
|
Compose.text(x, y, val)
|
||||||
))
|
))
|
||||||
end
|
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
|
for ann in anns
|
||||||
push!(plt.o.guides, createGadflyAnnotationObject(ann...))
|
push!(plt.o.guides, createGadflyAnnotationObject(ann...))
|
||||||
end
|
end
|
||||||
@ -491,7 +491,7 @@ getGadflyContext(::GadflyPackage, subplt::Subplot) = buildGadflySubplotContext(s
|
|||||||
# create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects
|
# create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects
|
||||||
function buildGadflySubplotContext(subplt::Subplot)
|
function buildGadflySubplotContext(subplt::Subplot)
|
||||||
i = 0
|
i = 0
|
||||||
rows = []
|
rows = Any[]
|
||||||
for rowcnt in subplt.layout.rowcounts
|
for rowcnt in subplt.layout.rowcounts
|
||||||
push!(rows, Gadfly.hstack([getGadflyContext(plt.backend, plt) for plt in subplt.plts[(1:rowcnt) + i]]...))
|
push!(rows, Gadfly.hstack([getGadflyContext(plt.backend, plt) for plt in subplt.plts[(1:rowcnt) + i]]...))
|
||||||
i += rowcnt
|
i += rowcnt
|
||||||
|
|||||||
@ -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
|
for ann in anns
|
||||||
push!(plt.o[2].guides, createGadflyAnnotationObject(ann...))
|
push!(plt.o[2].guides, createGadflyAnnotationObject(ann...))
|
||||||
end
|
end
|
||||||
|
|||||||
@ -55,7 +55,7 @@ supportedArgs(::PyPlotPackage) = [
|
|||||||
:yscale,
|
:yscale,
|
||||||
:xflip,
|
:xflip,
|
||||||
:yflip,
|
:yflip,
|
||||||
# :z,
|
:z,
|
||||||
]
|
]
|
||||||
supportedAxes(::PyPlotPackage) = _allAxes
|
supportedAxes(::PyPlotPackage) = _allAxes
|
||||||
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
|
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(c::Colorant) = map(f->float(f(c)), (red, green, blue, alpha))
|
||||||
getPyPlotColor(scheme::ColorScheme) = getPyPlotColor(getColor(scheme))
|
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)
|
# get the style (solid, dashed, etc)
|
||||||
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
||||||
linetype == :none && return " "
|
linetype == :none && return " "
|
||||||
@ -97,7 +102,7 @@ function getPyPlotMarker(marker::Symbol)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# pass through
|
# pass through
|
||||||
function getPyPlotMarker(marker::AbstractString)
|
function getPyPlotMarker(marker::@compat(AbstractString))
|
||||||
@assert length(marker) == 1
|
@assert length(marker) == 1
|
||||||
marker
|
marker
|
||||||
end
|
end
|
||||||
@ -119,26 +124,26 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
|||||||
if axis == :right
|
if axis == :right
|
||||||
ax = getRightAxis(plt.o[1])
|
ax = getRightAxis(plt.o[1])
|
||||||
ax[:set_ylabel](plt.initargs[:yrightlabel])
|
ax[:set_ylabel](plt.initargs[:yrightlabel])
|
||||||
fmap = Dict(
|
fmap = @compat Dict(
|
||||||
:hist => :hist,
|
:hist => :hist,
|
||||||
:sticks => :bar,
|
:sticks => :bar,
|
||||||
:bar => :bar,
|
:bar => :bar,
|
||||||
:heatmap => :hexbin,
|
:heatmap => :hexbin,
|
||||||
:hexbin => :hexbin,
|
:hexbin => :hexbin,
|
||||||
# :scatter => :scatter
|
:scatter => :scatter
|
||||||
)
|
)
|
||||||
return ax[get(fmap, linetype, :plot)]
|
return ax[get(fmap, linetype, :plot)]
|
||||||
# return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
|
# return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
|
||||||
end
|
end
|
||||||
|
|
||||||
# get the function
|
# get the function
|
||||||
fmap = Dict(
|
fmap = @compat Dict(
|
||||||
:hist => PyPlot.plt[:hist],
|
:hist => PyPlot.plt[:hist],
|
||||||
:sticks => PyPlot.bar,
|
:sticks => PyPlot.bar,
|
||||||
:bar => PyPlot.bar,
|
:bar => PyPlot.bar,
|
||||||
:heatmap => PyPlot.hexbin,
|
:heatmap => PyPlot.hexbin,
|
||||||
:hexbin => PyPlot.hexbin,
|
:hexbin => PyPlot.hexbin,
|
||||||
# :scatter => PyPlot.scatter
|
:scatter => PyPlot.scatter
|
||||||
)
|
)
|
||||||
return get(fmap, linetype, PyPlot.plot)
|
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))
|
# 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...)
|
d,_ = sticksHack(;d...)
|
||||||
|
|
||||||
elseif lt == :scatter
|
elseif lt == :scatter
|
||||||
d[:linetype] = :none
|
# d[:linetype] = :none
|
||||||
if d[:markershape] == :none
|
if d[:markershape] == :none
|
||||||
d[:markershape] = :ellipse
|
d[:markershape] = :ellipse
|
||||||
end
|
end
|
||||||
@ -251,11 +256,14 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
extraargs[:marker] = getPyPlotMarker(d[:markershape])
|
extraargs[:marker] = getPyPlotMarker(d[:markershape])
|
||||||
|
|
||||||
if lt == :scatter
|
if lt == :scatter
|
||||||
extraargs[:s] = d[:markersize]
|
extraargs[:s] = d[:markersize]^2
|
||||||
extraargs[:c] = getPyPlotColor(d[:markercolor])
|
#extraargs[:linewidths] = d[:linewidth]
|
||||||
extraargs[:linewidths] = d[:linewidth]
|
c = d[:markercolor]
|
||||||
if haskey(d, :colorscheme)
|
if isa(c, ColorGradient) && d[:z] != nothing
|
||||||
extraargs[:cmap] = d[:colorscheme]
|
extraargs[:c] = convert(Vector{Float64}, d[:z])
|
||||||
|
extraargs[:cmap] = getPyPlotColorMap(c)
|
||||||
|
else
|
||||||
|
extraargs[:c] = getPyPlotColor(c)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
extraargs[:markersize] = d[:markersize]
|
extraargs[:markersize] = d[:markersize]
|
||||||
@ -286,7 +294,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
fillrange = d[:fillrange]
|
fillrange = d[:fillrange]
|
||||||
if fillrange != nothing
|
if fillrange != nothing
|
||||||
fillcolor = getPyPlotColor(d[:fillcolor])
|
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)
|
ax[:fill_between](d[:x], fillrange, d[:y], facecolor = fillcolor)
|
||||||
else
|
else
|
||||||
ax[:fill_between](d[:x], fillrange..., facecolor = fillcolor)
|
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 = getLeftAxis(plt.o[1])
|
||||||
ax[:annotate](val, xy = (x,y))
|
ax[:annotate](val, xy = (x,y))
|
||||||
end
|
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
|
for ann in anns
|
||||||
createPyPlotAnnotationObject(plt, ann...)
|
createPyPlotAnnotationObject(plt, ann...)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -61,7 +61,7 @@ supportedScales(::QwtPackage) = [:identity, :log10]
|
|||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
const _qwtAliases = Dict(
|
@compat const _qwtAliases = Dict(
|
||||||
:nbins => :heatmap_n,
|
:nbins => :heatmap_n,
|
||||||
:fillrange => :fillto,
|
:fillrange => :fillto,
|
||||||
:linewidth => :width,
|
:linewidth => :width,
|
||||||
@ -210,14 +210,14 @@ function addLineMarker(plt::Plot{QwtPackage}, d::Dict)
|
|||||||
# marker[:attach](plt.o.widget)
|
# marker[:attach](plt.o.widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
function createQwtAnnotation(plt::Plot, x, y, val::AbstractString)
|
function createQwtAnnotation(plt::Plot, x, y, val::@compat(AbstractString))
|
||||||
marker = Qwt.QWT.QwtPlotMarker()
|
marker = Qwt.QWT.QwtPlotMarker()
|
||||||
marker[:setValue](x, y)
|
marker[:setValue](x, y)
|
||||||
marker[:setLabel](Qwt.QWT.QwtText(val))
|
marker[:setLabel](Qwt.QWT.QwtText(val))
|
||||||
marker[:attach](plt.o.widget)
|
marker[:attach](plt.o.widget)
|
||||||
end
|
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
|
for ann in anns
|
||||||
createQwtAnnotation(plt, ann...)
|
createQwtAnnotation(plt, ann...)
|
||||||
end
|
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)
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -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})
|
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{UnicodePlotsPackage})
|
||||||
|
|
||||||
# make some whitespace and show the plot
|
# make some whitespace and show the plot
|
||||||
|
|||||||
@ -12,13 +12,13 @@ winston() = backend(:winston)
|
|||||||
|
|
||||||
|
|
||||||
## dictionaries for conversion of Plots.jl names to Winston ones.
|
## 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",
|
:dash=>"dash",
|
||||||
:dot=>"dotted",
|
:dot=>"dotted",
|
||||||
:dashdot=>"dotdashed"
|
:dashdot=>"dotdashed"
|
||||||
)
|
)
|
||||||
|
|
||||||
const winston_marker = Dict(:none=>".",
|
@compat const winston_marker = Dict(:none=>".",
|
||||||
:rect => "square",
|
:rect => "square",
|
||||||
:ellipse=>"circle",
|
:ellipse=>"circle",
|
||||||
:diamond=>"diamond",
|
:diamond=>"diamond",
|
||||||
@ -215,7 +215,7 @@ end
|
|||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
const _winstonNames = Dict(
|
@compat const _winstonNames = Dict(
|
||||||
:xlims => :xrange,
|
:xlims => :xrange,
|
||||||
:ylims => :yrange,
|
:ylims => :yrange,
|
||||||
:xscale => :xlog,
|
: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)
|
Winston.text(x, y, val)
|
||||||
end
|
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
|
for ann in anns
|
||||||
createWinstonAnnotationObject(plt, ann...)
|
createWinstonAnnotationObject(plt, ann...)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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(c::Colorant) = c
|
||||||
convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
||||||
|
|
||||||
@ -92,8 +92,6 @@ convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
|||||||
abstract ColorScheme
|
abstract ColorScheme
|
||||||
|
|
||||||
getColor(scheme::ColorScheme) = getColor(scheme, 1)
|
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)]
|
getColorVector(scheme::ColorScheme) = [getColor(scheme)]
|
||||||
|
|
||||||
colorscheme(scheme::ColorScheme) = 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 _rainbowColors = [colorant"blue", colorant"purple", colorant"green", colorant"orange", colorant"red"]
|
||||||
|
|
||||||
const _gradients = Dict(
|
@compat const _gradients = Dict(
|
||||||
:blues => [colorant"lightblue", colorant"darkblue"],
|
:blues => [colorant"lightblue", colorant"darkblue"],
|
||||||
:reds => [colorant"lightpink", colorant"darkred"],
|
:reds => [colorant"lightpink", colorant"darkred"],
|
||||||
:greens => [colorant"lightgreen", colorant"darkgreen"],
|
:greens => [colorant"lightgreen", colorant"darkgreen"],
|
||||||
@ -182,6 +180,10 @@ getColorVector(gradient::ColorGradient) = gradient.colors
|
|||||||
# RGB(Lab(l, a, b))
|
# RGB(Lab(l, a, b))
|
||||||
# end
|
# 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)
|
function interpolate_rgb(c1::Colorant, c2::Colorant, w::Real)
|
||||||
rgb1 = RGBA(c1)
|
rgb1 = RGBA(c1)
|
||||||
rgb2 = RGBA(c2)
|
rgb2 = RGBA(c2)
|
||||||
|
|||||||
22
src/plot.jl
22
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:
|
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)
|
T = eltype(v)
|
||||||
# @show T
|
# @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]
|
# @show sym ticksym di[sym]
|
||||||
|
|
||||||
ticks = unique(di[sym])
|
ticks = unique(di[sym])
|
||||||
@ -177,9 +177,9 @@ updateDictWithMeta(d::Dict, initargs::Dict, meta, isx::Bool) = nothing
|
|||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
annotations(::Void) = []
|
annotations(::@compat(Void)) = []
|
||||||
annotations{X<:Real, Y<:Real, V}(v::AVec{Tuple{X,Y,V}}) = v
|
annotations{X<:Real, Y<:Real, V}(v::AVec{@compat(Tuple{X,Y,V})}) = v
|
||||||
annotations{X<:Real, Y<:Real, V}(t::Tuple{X,Y,V}) = [t]
|
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: ",
|
annotations(anns) = error("Expecting a tuple (or vector of tuples) for annotations: ",
|
||||||
"(x, y, annotation)\n got: $(typeof(anns))")
|
"(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
|
# 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
|
# 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
|
# missing
|
||||||
convertToAnyVector(v::Void; kw...) = Any[nothing], nothing
|
convertToAnyVector(v::@compat(Void); kw...) = Any[nothing], nothing
|
||||||
|
|
||||||
# fixed number of blank series
|
# fixed number of blank series
|
||||||
convertToAnyVector(n::Integer; kw...) = Any[zero(0) for i in 1:n], nothing
|
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
|
convertToAnyVector{T<:Real}(v::AVec{T}; kw...) = Any[v], nothing
|
||||||
|
|
||||||
# string vector
|
# 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
|
# numeric matrix
|
||||||
convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2)], nothing
|
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.
|
# 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.
|
# 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)
|
computeX(x, y) = copy(x)
|
||||||
computeY(x, y::Function) = map(y, x)
|
computeY(x, y::Function) = map(y, x)
|
||||||
computeY(x, y) = copy(y)
|
computeY(x, y) = copy(y)
|
||||||
@ -254,7 +254,7 @@ function createKWargsList(plt::PlottingObject, x, y; kw...)
|
|||||||
ys, ymeta = convertToAnyVector(y; kw...)
|
ys, ymeta = convertToAnyVector(y; kw...)
|
||||||
mx = length(xs)
|
mx = length(xs)
|
||||||
my = length(ys)
|
my = length(ys)
|
||||||
ret = []
|
ret = Any[]
|
||||||
for i in 1:max(mx, my)
|
for i in 1:max(mx, my)
|
||||||
|
|
||||||
# try to set labels using ymeta
|
# try to set labels using ymeta
|
||||||
@ -297,7 +297,7 @@ end
|
|||||||
|
|
||||||
# handle grouping
|
# handle grouping
|
||||||
function createKWargsList(plt::PlottingObject, groupby::GroupBy, args...; kw...)
|
function createKWargsList(plt::PlottingObject, groupby::GroupBy, args...; kw...)
|
||||||
ret = []
|
ret = Any[]
|
||||||
for (i,glab) in enumerate(groupby.groupLabels)
|
for (i,glab) in enumerate(groupby.groupLabels)
|
||||||
# TODO: don't automatically overwrite labels
|
# TODO: don't automatically overwrite labels
|
||||||
kwlist, xmeta, ymeta = createKWargsList(plt, args...; kw...,
|
kwlist, xmeta, ymeta = createKWargsList(plt, args...; kw...,
|
||||||
|
|||||||
@ -87,7 +87,7 @@ end
|
|||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
Returns the current plotting package name. Initializes package on first call.
|
Returns the current plotting package name. Initializes package on first call.
|
||||||
"""
|
"""
|
||||||
function backend()
|
function backend()
|
||||||
@ -101,51 +101,52 @@ function backend()
|
|||||||
try
|
try
|
||||||
@eval import Qwt
|
@eval import Qwt
|
||||||
@eval export Qwt
|
@eval export Qwt
|
||||||
catch
|
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)")
|
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
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :gadfly
|
elseif currentBackendSymbol == :gadfly
|
||||||
try
|
try
|
||||||
@eval import Gadfly, Compose
|
@eval import Gadfly, Compose
|
||||||
@eval export Gadfly, Compose
|
@eval export Gadfly, Compose
|
||||||
catch
|
catch err
|
||||||
error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\")")
|
error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\").\n Error: ", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :unicodeplots
|
elseif currentBackendSymbol == :unicodeplots
|
||||||
try
|
try
|
||||||
@eval import UnicodePlots
|
@eval import UnicodePlots
|
||||||
@eval export UnicodePlots
|
@eval export UnicodePlots
|
||||||
catch
|
catch err
|
||||||
error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\")")
|
error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\").\n Error: ", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :pyplot
|
elseif currentBackendSymbol == :pyplot
|
||||||
try
|
try
|
||||||
@eval import PyPlot
|
@eval import PyPlot
|
||||||
@eval export PyPlot
|
@eval export PyPlot
|
||||||
|
@eval const pycolors = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colors"))
|
||||||
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
||||||
PyPlot.ioff()
|
PyPlot.ioff()
|
||||||
end
|
end
|
||||||
catch
|
catch err
|
||||||
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\")")
|
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\").\n Error: ", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :immerse
|
elseif currentBackendSymbol == :immerse
|
||||||
try
|
try
|
||||||
@eval import Immerse, Gadfly, Compose, Gtk
|
@eval import Immerse, Gadfly, Compose, Gtk
|
||||||
@eval export Immerse, Gadfly, Compose, Gtk
|
@eval export Immerse, Gadfly, Compose, Gtk
|
||||||
catch
|
catch err
|
||||||
error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\")")
|
error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\").\n Error: ", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :winston
|
elseif currentBackendSymbol == :winston
|
||||||
try
|
try
|
||||||
@eval import Winston, Gtk
|
@eval import Winston, Gtk
|
||||||
@eval export Winston, Gtk
|
@eval export Winston, Gtk
|
||||||
catch
|
catch err
|
||||||
error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\")")
|
error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\").\n Error: ", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -158,7 +159,7 @@ function backend()
|
|||||||
CURRENT_BACKEND.pkg
|
CURRENT_BACKEND.pkg
|
||||||
end
|
end
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots
|
Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots
|
||||||
"""
|
"""
|
||||||
function backend(modname)
|
function backend(modname)
|
||||||
|
|||||||
@ -53,7 +53,7 @@ function validateSubplotSupported()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
Create a series of plots:
|
Create a series of plots:
|
||||||
```
|
```
|
||||||
y = rand(100,3)
|
y = rand(100,3)
|
||||||
@ -102,7 +102,7 @@ function subplot(args...; kw...)
|
|||||||
subplt
|
subplt
|
||||||
end
|
end
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
Adds to a subplot.
|
Adds to a subplot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
16
src/utils.jl
16
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]
|
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)
|
function binData(data, nbins)
|
||||||
lo, hi = extrema(data)
|
lo, hi = extrema(data)
|
||||||
edges = collect(linspace(lo, hi, nbins+1))
|
edges = collect(linspace(lo, hi, nbins+1))
|
||||||
@ -14,7 +14,7 @@ function binData(data, nbins)
|
|||||||
edges, midpoints, buckets, counts
|
edges, midpoints, buckets, counts
|
||||||
end
|
end
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
A hacky replacement for a histogram when the backend doesn't support histograms directly.
|
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.
|
Convert it into a bar chart with the appropriate x/y values.
|
||||||
"""
|
"""
|
||||||
@ -30,7 +30,7 @@ function histogramHack(; kw...)
|
|||||||
d
|
d
|
||||||
end
|
end
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
A hacky replacement for a bar graph when the backend doesn't support bars directly.
|
A hacky replacement for a bar graph when the backend doesn't support bars directly.
|
||||||
Convert it into a line chart with fillrange set.
|
Convert it into a line chart with fillrange set.
|
||||||
"""
|
"""
|
||||||
@ -70,7 +70,7 @@ function barHack(; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
doc"""
|
"""
|
||||||
A hacky replacement for a sticks graph when the backend doesn't support sticks directly.
|
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.
|
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"
|
"duplicate a single value, or pass the 2-tuple through"
|
||||||
maketuple(x::Real) = (x,x)
|
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)
|
function replaceAliases!(d::Dict, aliases::Dict)
|
||||||
@ -137,12 +137,12 @@ function regressionXY(x, y)
|
|||||||
regx, regy
|
regx, regy
|
||||||
end
|
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<: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
|
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
|
limsType(lims) = :invalid
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user