plotly 3d path/scatter, surface

This commit is contained in:
Thomas Breloff 2015-11-24 12:39:54 -05:00
parent cdc7920dff
commit 9d4c456461
5 changed files with 43 additions and 13 deletions

View File

@ -55,6 +55,10 @@ export
contour!,
surface,
surface!,
path3d,
path3d!,
scatter3d,
scatter3d!,
title!,
xlabel!,
@ -164,6 +168,10 @@ contour(args...; kw...) = plot(args...; kw..., linetype = :contour)
contour!(args...; kw...) = plot!(args...; kw..., linetype = :contour)
surface(args...; kw...) = plot(args...; kw..., linetype = :surface)
surface!(args...; kw...) = plot!(args...; kw..., linetype = :surface)
path3d(args...; kw...) = plot(args...; kw..., linetype = :path3d)
path3d!(args...; kw...) = plot!(args...; kw..., linetype = :path3d)
scatter3d(args...; kw...) = plot(args...; kw..., linetype = :scatter3d)
scatter3d!(args...; kw...) = plot!(args...; kw..., linetype = :scatter3d)
title!(s::@compat(AbstractString); kw...) = plot!(; title = s, kw...)

View File

@ -11,7 +11,7 @@ const _3dTypes = [:path3d, :scatter3d]
const _allTypes = vcat([
:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
:heatmap, :hexbin, :hist, :density, :bar, :hline, :vline, :ohlc,
:contour, :pie
:contour, :surface, :pie
], _3dTypes)
@compat const _typeAliases = Dict(
:n => :none,
@ -31,8 +31,9 @@ const _allTypes = vcat([
:dots => :scatter,
:histogram => :hist,
:pdf => :density,
:contours => :contours,
:contours => :contour,
:line3d => :path3d,
:surf => :surface,
)
ishistlike(lt::Symbol) = lt in (:hist, :density)

View File

@ -203,8 +203,9 @@ function get_series_html(d::Dict)
d_out[:name] = d[:label]
lt = d[:linetype]
hasmarker = lt == :scatter || d[:markershape] != :none
hasline = lt != :scatter
isscatter = lt in (:scatter, :scatter3d)
hasmarker = isscatter || d[:markershape] != :none
hasline = !isscatter
# set the "type"
if lt in (:line, :path, :scatter, :steppre, :steppost)
@ -246,14 +247,15 @@ function get_series_html(d::Dict)
d_out[:histnorm] = "probability density"
end
elseif lt == :contour
d_out[:type] = "contour"
elseif lt in (:contour, :surface)
d_out[:type] = string(lt)
d_out[:x], d_out[:y] = x, y
d_out[:z] = d[:z].surf
# d_out[:showscale] = d[:legend]
d_out[:ncontours] = d[:nlevels]
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
# TODO: colorscale: [[0, 'rgb(166,206,227)'], [0.25, 'rgb(31,120,180)'], [0.45, 'rgb(178,223,138)'], [0.65, 'rgb(51,160,44)'], [0.85, 'rgb(251,154,153)'], [1, 'rgb(227,26,28)']]
if lt == :contour
d_out[:ncontours] = d[:nlevels]
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
end
d_out[:colorscale] = plotly_colorscale(d[:linecolor])
elseif lt == :pie
@ -262,6 +264,16 @@ function get_series_html(d::Dict)
d_out[:values] = y
d_out[:hoverinfo] = "label+percent+name"
elseif lt in (:path3d, :scatter3d)
d_out[:type] = "scatter3d"
d_out[:mode] = if hasmarker
hasline ? "lines+markers" : "markers"
else
hasline ? "lines" : "none"
end
d_out[:x], d_out[:y] = x, y
d_out[:z] = collect(d[:z])
else
error("Plotly: linetype $lt isn't supported.")
end

View File

@ -483,7 +483,8 @@ supportedArgs(::PlotlyPackage) = [
]
supportedAxes(::PlotlyPackage) = [:auto, :left]
supportedTypes(::PlotlyPackage) = [:none, :path, :scatter, :steppre, :steppost,
:heatmap, :hist, :density, :bar, :contour, :pie] #,, :sticks, :hexbin, :hline, :vline]
:heatmap, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:pie] #,, :sticks, :hexbin, :hline, :vline]
supportedStyles(::PlotlyPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
:pentagon, :hexagon, :octagon] #vcat(_allMarkers, Shape)

View File

@ -352,9 +352,13 @@ function createKWargsList(plt::PlottingObject, y; kw...)
createKWargsList(plt, nothing, y; kw...)
end
# contours or surfaces... irregular data
# 3d line or scatter
function createKWargsList(plt::PlottingObject, x::AVec, y::AVec, zvec::AVec; kw...)
error("TODO: contours or surfaces... irregular data")
d = Dict(kw)
if !(get(d, :linetype, :none) in _3dTypes)
d[:linetype] = :path3d
end
createKWargsList(plt, x, y; z=zvec, d...)
end
# contours or surfaces... function grid
@ -377,7 +381,11 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
surf = Surface(convert(Matrix{Float64}, zmat))
# surf = Array(Any,1,1)
# surf[1,1] = convert(Matrix{Float64}, zmat)
createKWargsList(plt, x, y; kw..., z = surf, linetype = :contour)
d = Dict(kw)
if !(get(d, :linetype, :none) in (:contour, :surface))
d[:linetype] = :contour
end
createKWargsList(plt, x, y; d..., z = surf)
end
function createKWargsList(plt::PlottingObject, surf::Surface; kw...)