lims/ticks for gadfly/immerse

This commit is contained in:
Thomas Breloff 2015-09-23 12:45:24 -04:00
parent 80e8b5b5e4
commit a207856e99
7 changed files with 27 additions and 37 deletions

View File

@ -39,6 +39,10 @@ export
title!,
xlabel!,
ylabel!,
xlims!,
ylims!,
xticks!,
yticks!,
savepng,
gui,
@ -95,10 +99,18 @@ 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)
xlims!{T<:Real,S<:Real}(s::Tuple{T,S}) = plot!(xlims = s)
ylims!{T<:Real,S<:Real}(s::Tuple{T,S}) = plot!(ylims = s)
xticks!{T<:Real}(s::AVec{T}) = plot!(xticks = s)
yticks!{T<:Real}(s::AVec{T}) = plot!(yticks = s)
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, s::Tuple{T,S}) = plot!(plt; xlims = s)
ylims!{T<:Real,S<:Real}(plt::Plot, s::Tuple{T,S}) = plot!(plt; ylims = s)
xticks!{T<:Real}(plt::Plot, s::AVec{T}) = plot!(plt; xticks = s)
yticks!{T<:Real}(plt::Plot, s::AVec{T}) = plot!(plt; yticks = s)
# ---------------------------------------------------------

View File

@ -201,7 +201,11 @@ const _keyAliases = Dict(
:fg_color => :foreground_color,
:foreground => :foreground_color,
:xlim => :xlims,
:xlimit => :xlims,
:xlimits => :xlims,
:ylim => :ylims,
:ylimit => :ylims,
:ylimits => :ylims,
:xtick => :xticks,
:ytick => :yticks,
:windowsize => :size,

View File

@ -7,7 +7,7 @@ export gadfly!
gadfly!() = plotter!(:gadfly)
supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos])
supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos, :screen, :yrightlabel])
supportedAxes(::GadflyPackage) = setdiff(_allAxes, [:right])
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
@ -162,9 +162,6 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
(:ymin, Float64[min(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]),
(:ymax, Float64[max(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])])
]
# push!(d[:kwargs], (:ymin, Float64[min(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
# push!(d[:kwargs], (:ymax, Float64[max(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
# push!(d[:kwargs], (:ymax, Float64[max(y, fillto) for y in d[:y]]))
push!(gfargs, Gadfly.Geom.ribbon)
end
@ -193,38 +190,11 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
# add the layer to the Gadfly.Plot
# @show d[:kwargs]
# prepend!(gplt.layers, Gadfly.layer(unique(gfargs)..., d[:args]...; x = x, y = d[:y], d[:kwargs]...))
prepend!(gplt.layers, Gadfly.layer(unique(gfargs)...; x = x, y = d[:y], yminmax...))
# prepend!(gplt.layers, Gadfly.layer(unique(gfargs)...; x = x, y = d[:y]))
nothing
end
# function addTicksGuideOrScale(gplt, ticks, isx::Bool)
# ticks == :auto && return
# ttype = ticksType(ticks)
# if ttype == :limits
# minvalue = min(ticks...)
# maxvalue = max(ticks...)
# scale = (isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous)(minvalue=minvalue, maxvalue=maxvalue)
# push!(gplt.scales, scale)
# elseif ttype == :ticks
# # if isx
# # ticks = map(Compose.x_measure, sort(collect(ticks)))
# # push!(gplt.statistics, Gadfly.Stat.xticks(ticks=ticks))
# # else
# # ticks = map(Compose.y_measure, sort(collect(ticks)))
# # push!(gplt.statistics, Gadfly.Stat.yticks(ticks=ticks))
# # end
# ticks = sort(ticks)
# guide = (isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks)(ticks=ticks)
# push!(gplt.guides, guide)
# # stat = (isx ? Gadfly.Stat.xticks : Gadfly.Stat.yticks)(ticks=ticks)
# # push!(gplt.statistics, stat)
# else
# error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks)
# end
# end
function addTicksGuide(gplt, ticks, isx::Bool)
ticks == :auto && return
@ -238,13 +208,16 @@ function addTicksGuide(gplt, ticks, isx::Bool)
end
end
isContinuousScale(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScale) && scale.vars[1] == (isx ? :x : :y)
function addLimitsScale(gplt, lims, isx::Bool)
lims == :auto && return
ltype = limsType(lims)
if ltype == :limits
gtype = isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous
filter!(x -> !isa(x, gtype), gplt.scales)
push!(gplt.scales, gtype(minvalue = min(lims...), maxvalue = max(lims...)))
# remove any existing scales, then add a new one
gfunc = isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous
filter!(scale -> !isContinuousScale(scale,isx), gplt.scales)
push!(gplt.scales, gfunc(minvalue = min(lims...), maxvalue = max(lims...)))
else
error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims)
end

View File

@ -8,7 +8,7 @@ pyplot!() = plotter!(:pyplot)
# -------------------------------
supportedArgs(::PyPlotPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fillto, :pos])
supportedArgs(::PyPlotPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fillto, :pos, :xlims, :ylims, :xticks, :yticks])
supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]

View File

@ -6,6 +6,7 @@ immutable QwtPackage <: PlottingPackage end
export qwt!
qwt!() = plotter!(:qwt)
supportedArgs(::QwtPackage) = setdiff(_allArgs, [:xlims, :ylims, :xticks, :yticks])
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon]

View File

@ -8,7 +8,7 @@ unicodeplots!() = plotter!(:unicodeplots)
# -------------------------------
supportedArgs(::UnicodePlotsPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fillto, :pos])
supportedArgs(::UnicodePlotsPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fillto, :pos, :xlims, :ylims, :xticks, :yticks])
supportedAxes(::UnicodePlotsPackage) = [:auto, :left]
supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]
supportedStyles(::UnicodePlotsPackage) = [:auto, :solid]

View File

@ -30,7 +30,7 @@ const winston_marker = Dict(:none=>".",
)
supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fillto, :pos, :markercolor, :background_color])
supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fillto, :pos, :markercolor, :background_color, :xlims, :ylims, :xticks, :yticks])
supportedAxes(::WinstonPackage) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedStyles(::WinstonPackage) = intersect(_allStyles, collect(keys(winston_linestyle)))