diff --git a/src/Plots.jl b/src/Plots.jl index 33d58d19..840be7d2 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -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) # --------------------------------------------------------- diff --git a/src/args.jl b/src/args.jl index 77dcd87c..183166ed 100644 --- a/src/args.jl +++ b/src/args.jl @@ -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, diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 254ba5f0..36f5b9c3 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -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 diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 8ff8d914..f7f422d5 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -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] diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index 9854a27d..5b7cfb32 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -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] diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index fefb9989..54be4cd5 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -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] diff --git a/src/backends/winston.jl b/src/backends/winston.jl index 5b913ada..294e81ba 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -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)))