diff --git a/src/Plots.jl b/src/Plots.jl index f6986786..6b2d3bd7 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -77,6 +77,7 @@ export font, stroke, brush, + Surface, OHLC, colorscheme, diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 3534b86f..bcde38a0 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -120,7 +120,7 @@ function addGadflyLine!(plt::Plot, numlayers::Int, d::Dict, geoms...) kwargs[:xmax] = d[:x] + w elseif lt == :contour # d[:y] = reverse(d[:y]) - kwargs[:z] = d[:surface] + kwargs[:z] = d[:surface].surf addGadflyContColorScale(plt, d[:linecolor]) end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index d7a34526..4767eeaf 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -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), # and take the transpose of the surface matrix x, y = d[:x], d[:y] - surf = d[:surface]' + surf = d[:surface].surf' handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...) if d[:fillrange] != nothing handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])) diff --git a/src/components.jl b/src/components.jl index 7a22fcb3..8eedaa57 100644 --- a/src/components.jl +++ b/src/components.jl @@ -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} open::T high::T diff --git a/src/plot.jl b/src/plot.jl index 79e48860..e65556d1 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -232,6 +232,9 @@ convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2) # function convertToAnyVector(f::Function; kw...) = Any[f], nothing +# surface +convertToAnyVector(s::Surface; kw...) = Any[s], nothing + # vector of OHLC 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!") end x, y = computeX(x,y), computeY(x,y) - @assert length(x) == length(y) + # @assert length(x) == length(y) x, y end @@ -363,11 +366,16 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat:: @assert x == sort(x) @assert y == sort(y) @assert size(zmat) == (length(x), length(y)) - surf = Array(Any,1,1) - surf[1,1] = convert(Matrix{Float64}, zmat) + surf = Surface(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) 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...) error("Can't pass a Function or Vector{Function} for y without also passing x") end