working on ticks
This commit is contained in:
parent
88cfd82a25
commit
646b88c5be
@ -116,8 +116,8 @@ _plotDefaults[:yrightlabel] = ""
|
|||||||
_plotDefaults[:legend] = true
|
_plotDefaults[:legend] = true
|
||||||
_plotDefaults[:background_color] = colorant"white"
|
_plotDefaults[:background_color] = colorant"white"
|
||||||
_plotDefaults[:foreground_color] = :auto
|
_plotDefaults[:foreground_color] = :auto
|
||||||
_plotDefaults[:xticks] = true
|
_plotDefaults[:xticks] = :auto
|
||||||
_plotDefaults[:yticks] = true
|
_plotDefaults[:yticks] = :auto
|
||||||
_plotDefaults[:size] = (800,600)
|
_plotDefaults[:size] = (800,600)
|
||||||
_plotDefaults[:windowtitle] = "Plots.jl"
|
_plotDefaults[:windowtitle] = "Plots.jl"
|
||||||
_plotDefaults[:show] = false
|
_plotDefaults[:show] = false
|
||||||
@ -198,6 +198,8 @@ const _keyAliases = Dict(
|
|||||||
:fgcolor => :foreground_color,
|
:fgcolor => :foreground_color,
|
||||||
:fg_color => :foreground_color,
|
:fg_color => :foreground_color,
|
||||||
:foreground => :foreground_color,
|
:foreground => :foreground_color,
|
||||||
|
:xlim => :xticks,
|
||||||
|
:ylim => :yticks,
|
||||||
:windowsize => :size,
|
:windowsize => :size,
|
||||||
:wsize => :size,
|
:wsize => :size,
|
||||||
:wtitle => :windowtitle,
|
:wtitle => :windowtitle,
|
||||||
|
|||||||
@ -184,7 +184,6 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
|||||||
push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor])
|
push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# for histograms, set x=y
|
# for histograms, set x=y
|
||||||
x = d[d[:linetype] == :hist ? :y : :x]
|
x = d[d[:linetype] == :hist ? :y : :x]
|
||||||
|
|
||||||
@ -201,6 +200,32 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
|||||||
nothing
|
nothing
|
||||||
end
|
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 = map(Composesort(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
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
# create a blank Gadfly.Plot object
|
# create a blank Gadfly.Plot object
|
||||||
@ -233,6 +258,8 @@ function updateGadflyGuides(gplt, d::Dict)
|
|||||||
haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, d[:title])
|
haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, d[:title])
|
||||||
haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, d[:xlabel])
|
haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, d[:xlabel])
|
||||||
haskey(d, :ylabel) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, d[:ylabel])
|
haskey(d, :ylabel) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, d[:ylabel])
|
||||||
|
haskey(d, :xticks) && addTicksGuideOrScale(gplt, d[:xticks], true)
|
||||||
|
haskey(d, :yticks) && addTicksGuideOrScale(gplt, d[:yticks], true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function updatePlotItems(plt::Plot{GadflyPackage}, d::Dict)
|
function updatePlotItems(plt::Plot{GadflyPackage}, d::Dict)
|
||||||
|
|||||||
234
src/plot.jl
234
src/plot.jl
@ -259,237 +259,3 @@ end
|
|||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# doc"Build a vector of dictionaries which hold the keyword arguments for a call to plot!"
|
|
||||||
|
|
||||||
# # no args... 1 series
|
|
||||||
# function createKWargsList(plt::PlottingObject; kw...)
|
|
||||||
# d = Dict(kw)
|
|
||||||
# @assert haskey(d, :y)
|
|
||||||
# if !haskey(d, :x)
|
|
||||||
# d[:x] = 1:length(d[:y])
|
|
||||||
# end
|
|
||||||
# [getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), d, 1, plt.n + 1)]
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
|
||||||
# # ----------------------------------------------------------------------------
|
|
||||||
# # Arrays of numbers
|
|
||||||
# # ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# # create one series where y is vectors of numbers
|
|
||||||
# function createKWargsList{T<:Real}(plt::PlottingObject, y::AVec{T}; kw...)
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), kw, 1, plt.n + 1)
|
|
||||||
# d[:x] = 1:length(y)
|
|
||||||
# d[:y] = y
|
|
||||||
# [d]
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create one series where x/y are vectors of numbers
|
|
||||||
# function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AVec{T}, y::AVec{S}; kw...)
|
|
||||||
# @assert length(x) == length(y)
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), kw, 1, plt.n + 1)
|
|
||||||
# d[:x] = x
|
|
||||||
# d[:y] = y
|
|
||||||
# [d]
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create m series, 1 for each column of y
|
|
||||||
# function createKWargsList{T<:Real}(plt::PlottingObject, y::AMat{T}; kw...)
|
|
||||||
# n,m = size(y)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = 1:n
|
|
||||||
# d[:y] = y[:,i]
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create m series, 1 for each column of y
|
|
||||||
# function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AVec{T}, y::AMat{S}; kw...)
|
|
||||||
# n,m = size(y)
|
|
||||||
# @assert length(x) == n
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x
|
|
||||||
# d[:y] = y[:,i]
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create m series, 1 for each column of y
|
|
||||||
# function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{S}; kw...)
|
|
||||||
# @assert size(x) == size(y)
|
|
||||||
# n,m = size(y)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x[:,i]
|
|
||||||
# d[:y] = y[:,i]
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # ----------------------------------------------------------------------------
|
|
||||||
# # Functions
|
|
||||||
# # ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# # create 1 series, y = f(x), x ∈ [xmin, xmax]
|
|
||||||
# function createKWargsList(plt::PlottingObject, f::Function, xmin::Real, xmax::Real; kw...)
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), kw, 1, plt.n + 1)
|
|
||||||
# width = plt.initargs[:size][1]
|
|
||||||
# d[:x] = collect(linspace(xmin, xmax, width)) # we don't need more than the width
|
|
||||||
# d[:y] = map(f, d[:x])
|
|
||||||
# [d]
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create m series, yᵢ = fᵢ(x), x ∈ [xmin, xmax]
|
|
||||||
# function createKWargsList(plt::PlottingObject, fs::Vector{Function}, xmin::Real, xmax::Real; kw...)
|
|
||||||
# m = length(fs)
|
|
||||||
# ret = []
|
|
||||||
# width = plt.initargs[:size][1]
|
|
||||||
# x = collect(linspace(xmin, xmax, width)) # we don't need more than the width
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x
|
|
||||||
# d[:y] = map(fs[i], x)
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create 1 series, x = fx(u), y = fy(u); u ∈ [umin, umax]
|
|
||||||
# function createKWargsList(plt::PlottingObject, fx::Function, fy::Function, umin::Real, umax::Real; kw...)
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), kw, 1, plt.n + 1)
|
|
||||||
# width = plt.initargs[:size][1]
|
|
||||||
# u = collect(linspace(umin, umax, width)) # we don't need more than the width
|
|
||||||
# d[:x] = map(fx, u)
|
|
||||||
# d[:y] = map(fy, u)
|
|
||||||
# [d]
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # create 1 series, y = f(x)
|
|
||||||
# function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec{T}, f::Function; kw...)
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), kw, 1, plt.n + 1)
|
|
||||||
# d[:x] = x
|
|
||||||
# d[:y] = map(f, x)
|
|
||||||
# [d]
|
|
||||||
# end
|
|
||||||
# createKWargsList{T<:Real}(plt::PlottingObject, f::Function, x::AVec{T}; kw...) = createKWargsList(plt, x, f; kw...)
|
|
||||||
|
|
||||||
# # create m series, y = f(x), 1 for each column of x
|
|
||||||
# function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, f::Function; kw...)
|
|
||||||
# n,m = size(x)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x[:,i]
|
|
||||||
# d[:y] = map(f, d[:x])
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
# createKWargsList{T<:Real}(plt::PlottingObject, f::Function, x::AMat{T}; kw...) = createKWargsList(plt, x, f; kw...)
|
|
||||||
|
|
||||||
|
|
||||||
# # ----------------------------------------------------------------------------
|
|
||||||
# # Other combinations... lists of vectors, etc
|
|
||||||
# # ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# # create m series, 1 for each item in y (assumes vectors of something other than numbers... functions? vectors?)
|
|
||||||
# function createKWargsList(plt::PlottingObject, y::AVec; kw...)
|
|
||||||
# m = length(y)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = 1:length(y[i])
|
|
||||||
# d[:y] = y[i]
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# function getyvec(x::AVec, y::AVec)
|
|
||||||
# @assert length(x) == length(y)
|
|
||||||
# y
|
|
||||||
# end
|
|
||||||
# getyvec(x::AVec, f::Function) = map(f, x)
|
|
||||||
# getyvec(x, y) = error("Couldn't create yvec from types: x ($(typeof(x))), y ($(typeof(y)))")
|
|
||||||
|
|
||||||
# # same, but given an x to use for all series
|
|
||||||
# function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec{T}, y::AVec; kw...)
|
|
||||||
# m = length(y)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x
|
|
||||||
# d[:y] = getyvec(x, y[i])
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # x is vec of vec, but y is a matrix
|
|
||||||
# function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AMat{T}; kw...)
|
|
||||||
# n,m = size(y)
|
|
||||||
# @assert length(x) == m
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x[i]
|
|
||||||
# d[:y] = getyvec(x[i], y[:,i])
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # same, but m series of (x[i],y[i])
|
|
||||||
# function createKWargsList(plt::PlottingObject, x::AVec, y::AVec; kw...)
|
|
||||||
# @assert length(x) == length(y)
|
|
||||||
# m = length(y)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:m
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = x[i]
|
|
||||||
# d[:y] = getyvec(x[i], y[i])
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # n empty series
|
|
||||||
# function createKWargsList(plt::PlottingObject, n::Integer; kw...)
|
|
||||||
# ret = []
|
|
||||||
# for i in 1:n
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+i), kw, i, plt.n + i)
|
|
||||||
# d[:x] = zeros(0)
|
|
||||||
# d[:y] = zeros(0)
|
|
||||||
# push!(ret, d)
|
|
||||||
# end
|
|
||||||
# ret
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # vector of tuples... to be used for things like OHLC
|
|
||||||
# createKWargsList{T<:Tuple}(plt::PlottingObject, y::AVec{T}; kw...) = createKWargsList(plt, 1:length(y), y; kw...)
|
|
||||||
|
|
||||||
# function createKWargsList{S<:Real, T<:Tuple}(plt::PlottingObject, x::AVec{S}, y::AVec{T}; kw...)
|
|
||||||
# d = getSeriesArgs(plt.plotter, getinitargs(plt, plt.n+1), kw, 1, plt.n + 1)
|
|
||||||
# d[:x] = x
|
|
||||||
# d[:y] = y
|
|
||||||
# [d]
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: handle DataFrames (might have NAs!)
|
|
||||||
|
|
||||||
# -------------------------
|
|
||||||
|
|
||||||
|
|||||||
@ -128,6 +128,10 @@ function regressionXY(x, y)
|
|||||||
regx, regy
|
regx, regy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits
|
||||||
|
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
||||||
|
ticksType(ticks) = :invalid
|
||||||
|
|
||||||
|
|
||||||
# Some conversion functions
|
# Some conversion functions
|
||||||
# note: I borrowed these conversion constants from Compose.jl's Measure
|
# note: I borrowed these conversion constants from Compose.jl's Measure
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user