added wireframe linetype; support for surface and wireframe in pyplot
This commit is contained in:
parent
30ef8456c3
commit
002603c388
@ -53,6 +53,8 @@ export
|
|||||||
contour!,
|
contour!,
|
||||||
surface,
|
surface,
|
||||||
surface!,
|
surface!,
|
||||||
|
wireframe,
|
||||||
|
wireframe!,
|
||||||
path3d,
|
path3d,
|
||||||
path3d!,
|
path3d!,
|
||||||
scatter3d,
|
scatter3d,
|
||||||
@ -166,6 +168,8 @@ contour(args...; kw...) = plot(args...; kw..., linetype = :contour)
|
|||||||
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)
|
||||||
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)
|
||||||
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)
|
||||||
|
|||||||
@ -7,11 +7,11 @@ const _allAxes = [:auto, :left, :right]
|
|||||||
:r => :right
|
:r => :right
|
||||||
)
|
)
|
||||||
|
|
||||||
const _3dTypes = [:path3d, :scatter3d]
|
const _3dTypes = [:path3d, :scatter3d, :surface, :wireframe]
|
||||||
const _allTypes = vcat([
|
const _allTypes = vcat([
|
||||||
:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
|
:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
|
||||||
:heatmap, :hexbin, :hist, :density, :bar, :hline, :vline, :ohlc,
|
:heatmap, :hexbin, :hist, :density, :bar, :hline, :vline, :ohlc,
|
||||||
:contour, :surface, :pie
|
:contour, :pie
|
||||||
], _3dTypes)
|
], _3dTypes)
|
||||||
@compat const _typeAliases = Dict(
|
@compat const _typeAliases = Dict(
|
||||||
:n => :none,
|
:n => :none,
|
||||||
@ -34,6 +34,7 @@ const _allTypes = vcat([
|
|||||||
:contours => :contour,
|
:contours => :contour,
|
||||||
:line3d => :path3d,
|
:line3d => :path3d,
|
||||||
:surf => :surface,
|
:surf => :surface,
|
||||||
|
:wire => :wireframe,
|
||||||
)
|
)
|
||||||
|
|
||||||
ishistlike(lt::Symbol) = lt in (:hist, :density)
|
ishistlike(lt::Symbol) = lt in (:hist, :density)
|
||||||
|
|||||||
@ -276,8 +276,8 @@ function get_series_json(d::Dict; plot_index = nothing)
|
|||||||
d_out[:histnorm] = "probability density"
|
d_out[:histnorm] = "probability density"
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif lt in (:contour, :surface)
|
elseif lt in (:contour, :surface, :wireframe)
|
||||||
d_out[:type] = string(lt)
|
d_out[:type] = lt == :wireframe ? :surface : string(lt)
|
||||||
d_out[:x], d_out[:y] = x, y
|
d_out[:x], d_out[:y] = x, y
|
||||||
d_out[:z] = d[:z].surf
|
d_out[:z] = d[:z].surf
|
||||||
# d_out[:showscale] = d[:legend]
|
# 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[:ncontours] = d[:nlevels]
|
||||||
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
||||||
end
|
end
|
||||||
d_out[:colorscale] = plotly_colorscale(d[:linecolor])
|
d_out[:colorscale] = plotly_colorscale(d[lt == :contour ? :linecolor : :fillcolor])
|
||||||
|
|
||||||
elseif lt == :pie
|
elseif lt == :pie
|
||||||
d_out[:type] = "pie"
|
d_out[:type] = "pie"
|
||||||
|
|||||||
@ -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>"
|
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
|
||||||
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
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>]
|
# in the 2-axis case we need to get: <rightaxis>[:<func>]
|
||||||
ax = getAxis(plt, axis)
|
ax = getAxis(plt, axis)
|
||||||
# ax[:set_ylabel](plt.plotargs[:yrightlabel])
|
# ax[:set_ylabel](plt.plotargs[:yrightlabel])
|
||||||
@ -134,6 +139,9 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
|||||||
:scatter => :scatter,
|
:scatter => :scatter,
|
||||||
:contour => :contour,
|
:contour => :contour,
|
||||||
:scatter3d => :scatter,
|
:scatter3d => :scatter,
|
||||||
|
:surface => :plot_surface,
|
||||||
|
:wireframe => :plot_wireframe,
|
||||||
|
# :surface => pycolors.pymember("LinearSegmentedColormap")[:from_list]
|
||||||
)
|
)
|
||||||
return ax[get(fmap, linetype, :plot)]
|
return ax[get(fmap, linetype, :plot)]
|
||||||
end
|
end
|
||||||
@ -269,6 +277,15 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
extra_kwargs[:linestyles] = getPyPlotLineStyle(lt, d[:linestyle])
|
extra_kwargs[:linestyles] = getPyPlotLineStyle(lt, d[:linestyle])
|
||||||
# TODO: will need to call contourf to fill in the contours
|
# 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
|
else
|
||||||
|
|
||||||
extra_kwargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle])
|
extra_kwargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle])
|
||||||
@ -304,7 +321,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
# set these for all types
|
# set these for all types
|
||||||
if lt != :contour
|
if !(lt in (:contour,:surface,:wireframe))
|
||||||
if !(lt in (:scatter, :scatter3d))
|
if !(lt in (:scatter, :scatter3d))
|
||||||
extra_kwargs[:color] = color
|
extra_kwargs[:color] = color
|
||||||
extra_kwargs[:linewidth] = d[:linewidth]
|
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]))
|
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
|
||||||
end
|
end
|
||||||
handle
|
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
|
elseif lt in _3dTypes
|
||||||
plotfunc(d[:x], d[:y], d[:z]; extra_kwargs...)
|
plotfunc(d[:x], d[:y], d[:z]; extra_kwargs...)
|
||||||
elseif lt in (:scatter, :heatmap, :hexbin)
|
elseif lt in (:scatter, :heatmap, :hexbin)
|
||||||
|
|||||||
@ -162,7 +162,7 @@ supportedArgs(::PyPlotPackage) = [
|
|||||||
supportedAxes(::PyPlotPackage) = _allAxes
|
supportedAxes(::PyPlotPackage) = _allAxes
|
||||||
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
||||||
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
|
: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]
|
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
|
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
|
||||||
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
|
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
|
||||||
|
|||||||
@ -229,6 +229,8 @@ immutable Surface{M<:AMat}
|
|||||||
surf::M
|
surf::M
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Surface(f::Function, x, y) = Surface(Float64[f(xi,yi) for xi in x, yi in y])
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
|
|
||||||
type OHLC{T<:Real}
|
type OHLC{T<:Real}
|
||||||
|
|||||||
@ -382,7 +382,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, 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)
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
if !(get(d, :linetype, :none) in (:contour, :surface))
|
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
|
||||||
d[:linetype] = :contour
|
d[:linetype] = :contour
|
||||||
end
|
end
|
||||||
createKWargsList(plt, x, y; d..., z = surf)
|
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...)
|
createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...)
|
||||||
end
|
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...)
|
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
|
||||||
|
|||||||
@ -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()
|
function pickDefaultBackend()
|
||||||
for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh")
|
for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh")
|
||||||
if Pkg.installed(pkgstr) != nothing
|
if Pkg.installed(pkgstr) != nothing
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user