surface arg is now z; added orientation arg; working on plotly

This commit is contained in:
Thomas Breloff 2015-11-22 22:34:30 -05:00
parent 1db2d8d8d8
commit 4b1f127eaf
8 changed files with 89 additions and 62 deletions

View File

@ -133,8 +133,9 @@ _seriesDefaults[:x] = nothing
_seriesDefaults[:y] = nothing _seriesDefaults[:y] = nothing
_seriesDefaults[:z] = nothing # depth for contour, surface, etc _seriesDefaults[:z] = nothing # depth for contour, surface, etc
_seriesDefaults[:zcolor] = nothing # value for color scale _seriesDefaults[:zcolor] = nothing # value for color scale
_seriesDefaults[:surface] = nothing # _seriesDefaults[:surface] = nothing
_seriesDefaults[:nlevels] = 15 _seriesDefaults[:nlevels] = 15
_seriesDefaults[:orientation] = :vertical
const _plotDefaults = Dict{Symbol, Any}() const _plotDefaults = Dict{Symbol, Any}()

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].surf kwargs[:z] = d[:z].surf
addGadflyContColorScale(plt, d[:linecolor]) addGadflyContColorScale(plt, d[:linecolor])
end end

View File

@ -175,28 +175,55 @@ end
# _seriesDefaults[:surface] = nothing # _seriesDefaults[:surface] = nothing
# _seriesDefaults[:nlevels] = 15 # _seriesDefaults[:nlevels] = 15
function get_series_html(plt::Plot{PlotlyPackage}) # supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
JSON.json([begin # :scatter, :heatmap, :hexbin, :hist, :density, :bar,
# :hline, :vline, :contour, :path3d, :scatter3d]
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
function get_series_html(d::Dict)
d_out = Dict() d_out = Dict()
# TODO: set the fields for each series x, y = collect(d[:x]), collect(d[:y])
d_out[:x] = collect(d[:x]) # d_out[:x] = collect(d[:x])
d_out[:y] = collect(d[:y]) # d_out[:y] = collect(d[:y])
d_out[:name] = d[:label] d_out[:name] = d[:label]
lt = d[:linetype] lt = d[:linetype]
if lt in (:line, :path, :scatter, :steppre, :steppost)
d_out[:type] = "scatter"
end
hasmarker = lt == :scatter || d[:markershape] != :none hasmarker = lt == :scatter || d[:markershape] != :none
hasline = lt != :scatter hasline = lt != :scatter
# set the "type"
if lt in (:line, :path, :scatter, :steppre, :steppost)
d_out[:type] = "scatter"
d_out[:mode] = if hasmarker d_out[:mode] = if hasmarker
hasline ? "lines+markers" : "markers" hasline ? "lines+markers" : "markers"
else else
hasline ? "lines" : "none" hasline ? "lines" : "none"
end end
d_out[:x], d_out[:y] = x, y
elseif lt == :bar
d_out[:type] = "bar"
d_out[:x], d_out[:y] = x, y
elseif lt == :heatmap
d_out[:type] = "heatmap"
d_out[:x], d_out[:y] = x, y
elseif lt == :hist
d_out[:type] = "histogram"
isvert = d[:orientation] in (:vertical, :v, :vert)
d_out[isvert ? :x : :y] = y
elseif lt == :contour
d_out[:type] = "contour"
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)']]
else
error("Plotly: linetype $lt isn't supported.")
end
# add "marker"
if hasmarker if hasmarker
d_out[:marker] = Dict( d_out[:marker] = Dict(
# :symbol => "circle", # :symbol => "circle",
@ -214,6 +241,7 @@ function get_series_html(plt::Plot{PlotlyPackage})
end end
end end
# add "line"
if hasline if hasline
d_out[:line] = Dict( d_out[:line] = Dict(
:color => webcolor(d[:linecolor], d[:linealpha]), :color => webcolor(d[:linecolor], d[:linealpha]),
@ -223,7 +251,11 @@ function get_series_html(plt::Plot{PlotlyPackage})
end end
d_out d_out
end for d in plt.seriesargs]) end
# get a list of dictionaries, each representing the series params
function get_series_html(plt::Plot{PlotlyPackage})
JSON.json(map(get_series_html, plt.seriesargs))
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
@ -249,6 +281,12 @@ end
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{PlotlyPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{PlotlyPackage})
# TODO: write a png to io # TODO: write a png to io
println("png")
end
function Base.writemime(io::IO, ::MIME"text/html", plt::PlottingObject{PlotlyPackage})
println("html")
html_head(plt) * html_body(plt)
end end
function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage}) function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage})

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' surf = d[:z].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

@ -71,7 +71,7 @@ supportedArgs(::GadflyPackage) = [
:guidefont, :guidefont,
:legendfont, :legendfont,
:grid, :grid,
:surface, # :surface,
:nlevels, :nlevels,
] ]
supportedAxes(::GadflyPackage) = [:auto, :left] supportedAxes(::GadflyPackage) = [:auto, :left]
@ -151,7 +151,7 @@ supportedArgs(::PyPlotPackage) = [
:guidefont, :guidefont,
:legendfont, :legendfont,
:grid, :grid,
:surface, # :surface,
:nlevels, :nlevels,
:fillalpha, :fillalpha,
:linealpha, :linealpha,

View File

@ -3,21 +3,6 @@
# CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl
using JSON
# const _html_template = mt"""
# <!DOCTYPE html>
# <html>
# <head>
# <title>{{:title}}</title>
# {{:head}}
# </head>
# <body>
# {{:body}}
# </body>
# </html>
# """
function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl")) function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl"))
""" """

View File

@ -369,7 +369,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
surf = Surface(convert(Matrix{Float64}, zmat)) surf = Surface(convert(Matrix{Float64}, zmat))
# surf = Array(Any,1,1) # surf = Array(Any,1,1)
# surf[1,1] = convert(Matrix{Float64}, zmat) # surf[1,1] = convert(Matrix{Float64}, zmat)
createKWargsList(plt, x, y; kw..., surface = surf, linetype = :contour) createKWargsList(plt, x, y; kw..., z = surf, linetype = :contour)
end end
function createKWargsList(plt::PlottingObject, surf::Surface; kw...) function createKWargsList(plt::PlottingObject, surf::Surface; kw...)

View File

@ -48,8 +48,10 @@ include("backends/unicodeplots.jl")
include("backends/pyplot.jl") include("backends/pyplot.jl")
include("backends/immerse.jl") include("backends/immerse.jl")
include("backends/winston.jl") include("backends/winston.jl")
include("backends/web.jl")
include("backends/bokeh.jl") include("backends/bokeh.jl")
# include("backends/plotly.jl") include("backends/plotly.jl")
# --------------------------------------------------------- # ---------------------------------------------------------
@ -236,8 +238,9 @@ function backend()
elseif currentBackendSymbol == :plotly elseif currentBackendSymbol == :plotly
try try
@eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl")) # @eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl"))
@eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) # @eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl"))
@eval import JSON
catch err catch err
warn("Couldn't setup Plotly") warn("Couldn't setup Plotly")
rethrow(err) rethrow(err)