added wireframe linetype; support for surface and wireframe in pyplot

This commit is contained in:
Thomas Breloff 2015-12-17 11:55:26 -05:00
parent 30ef8456c3
commit 002603c388
8 changed files with 38 additions and 43 deletions

View File

@ -53,6 +53,8 @@ export
contour!,
surface,
surface!,
wireframe,
wireframe!,
path3d,
path3d!,
scatter3d,
@ -166,6 +168,8 @@ 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)
wireframe(args...; kw...) = plot(args...; kw..., linetype = :wireframe)
wireframe!(args...; kw...) = plot!(args...; kw..., linetype = :wireframe)
path3d(args...; kw...) = plot(args...; kw..., linetype = :path3d)
path3d!(args...; kw...) = plot!(args...; kw..., linetype = :path3d)
scatter3d(args...; kw...) = plot(args...; kw..., linetype = :scatter3d)

View File

@ -7,11 +7,11 @@ const _allAxes = [:auto, :left, :right]
:r => :right
)
const _3dTypes = [:path3d, :scatter3d]
const _3dTypes = [:path3d, :scatter3d, :surface, :wireframe]
const _allTypes = vcat([
:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
:heatmap, :hexbin, :hist, :density, :bar, :hline, :vline, :ohlc,
:contour, :surface, :pie
:contour, :pie
], _3dTypes)
@compat const _typeAliases = Dict(
:n => :none,
@ -34,6 +34,7 @@ const _allTypes = vcat([
:contours => :contour,
:line3d => :path3d,
:surf => :surface,
:wire => :wireframe,
)
ishistlike(lt::Symbol) = lt in (:hist, :density)

View File

@ -276,8 +276,8 @@ function get_series_json(d::Dict; plot_index = nothing)
d_out[:histnorm] = "probability density"
end
elseif lt in (:contour, :surface)
d_out[:type] = string(lt)
elseif lt in (:contour, :surface, :wireframe)
d_out[:type] = lt == :wireframe ? :surface : string(lt)
d_out[:x], d_out[:y] = x, y
d_out[:z] = d[:z].surf
# d_out[:showscale] = d[:legend]
@ -285,7 +285,7 @@ function get_series_json(d::Dict; plot_index = nothing)
d_out[:ncontours] = d[:nlevels]
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
end
d_out[:colorscale] = plotly_colorscale(d[:linecolor])
d_out[:colorscale] = plotly_colorscale(d[lt == :contour ? :linecolor : :fillcolor])
elseif lt == :pie
d_out[:type] = "pie"

View File

@ -121,6 +121,11 @@ getAxis(plt::Plot{PyPlotPackage}, axis::Symbol) = (axis == :right ? getRightAxis
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
# # need to access mplot3d functions differently
# if linetype == :surface
# return mplot3d.pymember("Axes3D")[:plot_surface]
# end
# in the 2-axis case we need to get: <rightaxis>[:<func>]
ax = getAxis(plt, axis)
# ax[:set_ylabel](plt.plotargs[:yrightlabel])
@ -134,6 +139,9 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
:scatter => :scatter,
:contour => :contour,
:scatter3d => :scatter,
:surface => :plot_surface,
:wireframe => :plot_wireframe,
# :surface => pycolors.pymember("LinearSegmentedColormap")[:from_list]
)
return ax[get(fmap, linetype, :plot)]
end
@ -269,6 +277,15 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
extra_kwargs[:linestyles] = getPyPlotLineStyle(lt, d[:linestyle])
# TODO: will need to call contourf to fill in the contours
elseif lt in (:surface, :wireframe)
if lt == :surface
extra_kwargs[:cmap] = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])
end
extra_kwargs[:rstride] = 1
extra_kwargs[:cstride] = 1
extra_kwargs[:linewidth] = d[:linewidth]
extra_kwargs[:edgecolor] = getPyPlotColor(d[:linecolor], d[:linealpha])
else
extra_kwargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle])
@ -304,7 +321,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
# end
# set these for all types
if lt != :contour
if !(lt in (:contour,:surface,:wireframe))
if !(lt in (:scatter, :scatter3d))
extra_kwargs[:color] = color
extra_kwargs[:linewidth] = d[:linewidth]
@ -326,6 +343,8 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
end
handle
elseif lt in (:surface,:wireframe)
plotfunc(repmat(d[:x]',length(d[:y]),1), repmat(d[:y],1,length(d[:x])), d[:z].surf'; extra_kwargs...)
elseif lt in _3dTypes
plotfunc(d[:x], d[:y], d[:z]; extra_kwargs...)
elseif lt in (:scatter, :heatmap, :hexbin)

View File

@ -162,7 +162,7 @@ supportedArgs(::PyPlotPackage) = [
supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
:hline, :vline, :contour, :path3d, :scatter3d]
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)

View File

@ -229,6 +229,8 @@ immutable Surface{M<:AMat}
surf::M
end
Surface(f::Function, x, y) = Surface(Float64[f(xi,yi) for xi in x, yi in y])
# -----------------------------------------------------------------------
type OHLC{T<:Real}

View File

@ -382,7 +382,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
# surf = Array(Any,1,1)
# surf[1,1] = convert(Matrix{Float64}, zmat)
d = Dict(kw)
if !(get(d, :linetype, :none) in (:contour, :surface))
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
d[:linetype] = :contour
end
createKWargsList(plt, x, y; d..., z = surf)
@ -392,6 +392,10 @@ 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, x::AVec, y::AVec, surf::Surface; kw...)
createKWargsList(plt, x, y, 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

View File

@ -98,41 +98,6 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, backendInstance(sym))
# ---------------------------------------------------------
# function pickDefaultBackend()
# try
# if Pkg.installed("PyPlot") != nothing
# return CurrentBackend(:pyplot)
# end
# end
# try
# if Pkg.installed("Immerse") != nothing
# return CurrentBackend(:immerse)
# end
# end
# try
# if Pkg.installed("Qwt") != nothing
# return CurrentBackend(:qwt)
# end
# end
# try
# if Pkg.installed("Gadfly") != nothing
# return CurrentBackend(:gadfly)
# end
# end
# try
# if Pkg.installed("UnicodePlots") != nothing
# return CurrentBackend(:unicodeplots)
# end
# end
# try
# if Pkg.installed("Bokeh") != nothing
# return CurrentBackend(:bokeh)
# end
# end
# # warn("You don't have any of the supported backends installed! Chose from ", backends())
# return CurrentBackend(:plotly)
# end
function pickDefaultBackend()
for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh")
if Pkg.installed(pkgstr) != nothing