added Surface, removed x/y length assert; added Surface createKWargsList; closes #82

This commit is contained in:
Thomas Breloff 2015-11-22 11:21:07 -05:00
parent 6beadcece8
commit 87bb45d01b
5 changed files with 23 additions and 5 deletions

View File

@ -77,6 +77,7 @@ export
font, font,
stroke, stroke,
brush, brush,
Surface,
OHLC, OHLC,
colorscheme, colorscheme,

View File

@ -120,7 +120,7 @@ function addGadflyLine!(plt::Plot, numlayers::Int, d::Dict, geoms...)
kwargs[:xmax] = d[:x] + w kwargs[:xmax] = d[:x] + w
elseif lt == :contour elseif lt == :contour
# d[:y] = reverse(d[:y]) # d[:y] = reverse(d[:y])
kwargs[:z] = d[:surface] kwargs[:z] = d[:surface].surf
addGadflyContColorScale(plt, d[:linecolor]) addGadflyContColorScale(plt, d[:linecolor])
end end

View File

@ -320,7 +320,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
# NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed), # NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed),
# and take the transpose of the surface matrix # and take the transpose of the surface matrix
x, y = d[:x], d[:y] x, y = d[:x], d[:y]
surf = d[:surface]' surf = d[:surface].surf'
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...) handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...)
if d[:fillrange] != nothing if d[:fillrange] != nothing
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])) handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))

View File

@ -220,6 +220,15 @@ end
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
"represents a contour or surface mesh"
immutable Surface{M<:AMat}
# x::AVec
# y::AVec
surf::M
end
# -----------------------------------------------------------------------
type OHLC{T<:Real} type OHLC{T<:Real}
open::T open::T
high::T high::T

View File

@ -232,6 +232,9 @@ convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2)
# function # function
convertToAnyVector(f::Function; kw...) = Any[f], nothing convertToAnyVector(f::Function; kw...) = Any[f], nothing
# surface
convertToAnyVector(s::Surface; kw...) = Any[s], nothing
# vector of OHLC # vector of OHLC
convertToAnyVector(v::AVec{OHLC}; kw...) = Any[v], nothing convertToAnyVector(v::AVec{OHLC}; kw...) = Any[v], nothing
@ -260,7 +263,7 @@ function computeXandY(x, y)
error("If you want to plot the function `$y`, you need to define the x values somehow!") error("If you want to plot the function `$y`, you need to define the x values somehow!")
end end
x, y = computeX(x,y), computeY(x,y) x, y = computeX(x,y), computeY(x,y)
@assert length(x) == length(y) # @assert length(x) == length(y)
x, y x, y
end end
@ -363,11 +366,16 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
@assert x == sort(x) @assert x == sort(x)
@assert y == sort(y) @assert y == sort(y)
@assert size(zmat) == (length(x), length(y)) @assert size(zmat) == (length(x), length(y))
surf = Array(Any,1,1) surf = Surface(convert(Matrix{Float64}, zmat))
surf[1,1] = convert(Matrix{Float64}, zmat) # surf = Array(Any,1,1)
# surf[1,1] = convert(Matrix{Float64}, zmat)
createKWargsList(plt, x, y; kw..., surface = surf, linetype = :contour) createKWargsList(plt, x, y; kw..., surface = surf, linetype = :contour)
end end
function createKWargsList(plt::PlottingObject, surf::Surface; kw...)
createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...)
end
function createKWargsList(plt::PlottingObject, f::FuncOrFuncs; kw...) function createKWargsList(plt::PlottingObject, f::FuncOrFuncs; kw...)
error("Can't pass a Function or Vector{Function} for y without also passing x") error("Can't pass a Function or Vector{Function} for y without also passing x")
end end