InputWrapper and pyplot surface zcolor
This commit is contained in:
parent
db118d4f5a
commit
005ce11313
@ -20,6 +20,8 @@ export
|
|||||||
AVec,
|
AVec,
|
||||||
AMat,
|
AMat,
|
||||||
KW,
|
KW,
|
||||||
|
|
||||||
|
wrap,
|
||||||
set_theme,
|
set_theme,
|
||||||
add_theme,
|
add_theme,
|
||||||
|
|
||||||
|
|||||||
@ -754,19 +754,21 @@ end
|
|||||||
|
|
||||||
# 1-row matrices will give an element
|
# 1-row matrices will give an element
|
||||||
# multi-row matrices will give a column
|
# multi-row matrices will give a column
|
||||||
|
# InputWrapper just gives the contents
|
||||||
# anything else is returned as-is
|
# anything else is returned as-is
|
||||||
# getArgValue(v::Tuple, idx::Int) = v[mod1(idx, length(v))]
|
# getArgValue(v::Tuple, idx::Int) = v[mod1(idx, length(v))]
|
||||||
function getArgValue(v::AMat, idx::Int)
|
function getArgValue(v::AMat, idx::Int)
|
||||||
c = mod1(idx, size(v,2))
|
c = mod1(idx, size(v,2))
|
||||||
size(v,1) == 1 ? v[1,c] : v[:,c]
|
size(v,1) == 1 ? v[1,c] : v[:,c]
|
||||||
end
|
end
|
||||||
|
getArgValue(wrapper::InputWrapper, idx) = wrapper.obj
|
||||||
getArgValue(v, idx) = v
|
getArgValue(v, idx) = v
|
||||||
|
|
||||||
|
|
||||||
# given an argument key (k), we want to extract the argument value for this index.
|
# given an argument key (k), we want to extract the argument value for this index.
|
||||||
# if nothing is set (or container is empty), return the default.
|
# if nothing is set (or container is empty), return the default.
|
||||||
function setDictValue(d_in::KW, d_out::KW, k::Symbol, idx::Int, defaults::KW)
|
function setDictValue(d_in::KW, d_out::KW, k::Symbol, idx::Int, defaults::KW)
|
||||||
if haskey(d_in, k) && !(typeof(d_in[k]) <: @compat(Union{AbstractArray, Tuple}) && isempty(d_in[k]))
|
if haskey(d_in, k) && !(typeof(d_in[k]) <: Union{AbstractArray, Tuple} && isempty(d_in[k]))
|
||||||
d_out[k] = getArgValue(d_in[k], idx)
|
d_out[k] = getArgValue(d_in[k], idx)
|
||||||
else
|
else
|
||||||
d_out[k] = defaults[k]
|
d_out[k] = defaults[k]
|
||||||
|
|||||||
@ -11,7 +11,8 @@ function _initialize_backend(::PyPlotBackend)
|
|||||||
const pypatches = PyPlot.pywrap(PyPlot.pyimport("matplotlib.patches"))
|
const pypatches = PyPlot.pywrap(PyPlot.pyimport("matplotlib.patches"))
|
||||||
const pyfont = PyPlot.pywrap(PyPlot.pyimport("matplotlib.font_manager"))
|
const pyfont = PyPlot.pywrap(PyPlot.pyimport("matplotlib.font_manager"))
|
||||||
const pyticker = PyPlot.pywrap(PyPlot.pyimport("matplotlib.ticker"))
|
const pyticker = PyPlot.pywrap(PyPlot.pyimport("matplotlib.ticker"))
|
||||||
# const pycolorbar = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colorbar"))
|
const pycmap = PyPlot.pywrap(PyPlot.pyimport("matplotlib.cm"))
|
||||||
|
const pynp = PyPlot.pywrap(PyPlot.pyimport("numpy"))
|
||||||
end
|
end
|
||||||
|
|
||||||
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
||||||
@ -51,6 +52,15 @@ getPyPlotColorMap(v::AVec, α=nothing) = getPyPlotColorMap(ColorGradient(v), α)
|
|||||||
# anything else just gets a bluesred gradient
|
# anything else just gets a bluesred gradient
|
||||||
getPyPlotColorMap(c, α=nothing) = getPyPlotColorMap(default_gradient(), α)
|
getPyPlotColorMap(c, α=nothing) = getPyPlotColorMap(default_gradient(), α)
|
||||||
|
|
||||||
|
function getPyPlotCustomShading(c, z, α=nothing)
|
||||||
|
cmap = getPyPlotColorMap(c, α)
|
||||||
|
# sm = pycmap.pymember("ScalarMappable")(cmap = cmap)
|
||||||
|
# sm[:set_array](z)
|
||||||
|
# sm
|
||||||
|
ls = pycolors.pymember("LightSource")(270,45)
|
||||||
|
ls[:shade](z, cmap, vert_exag=0.1, blend_mode="soft")
|
||||||
|
end
|
||||||
|
|
||||||
# get the style (solid, dashed, etc)
|
# get the style (solid, dashed, etc)
|
||||||
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
||||||
linetype == :none && return " "
|
linetype == :none && return " "
|
||||||
@ -508,9 +518,14 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
|
|||||||
z = z'
|
z = z'
|
||||||
end
|
end
|
||||||
if lt == :surface
|
if lt == :surface
|
||||||
|
if d[:marker_z] != nothing
|
||||||
|
extrakw[:facecolors] = getPyPlotCustomShading(d[:fillcolor], d[:marker_z], d[:fillalpha])
|
||||||
|
extrakw[:shade] = false
|
||||||
|
else
|
||||||
extrakw[:cmap] = pyfillcolormap(d)
|
extrakw[:cmap] = pyfillcolormap(d)
|
||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
handle = ax[lt == :surface ? :plot_surface : :plot_wireframe](x, y, z;
|
handle = ax[lt == :surface ? :plot_surface : :plot_wireframe](x, y, z;
|
||||||
label = d[:label],
|
label = d[:label],
|
||||||
zorder = plt.n,
|
zorder = plt.n,
|
||||||
@ -536,6 +551,11 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# no colorbar if we are creating a surface LightSource
|
||||||
|
if haskey(extrakw, :facecolors)
|
||||||
|
needs_colorbar = false
|
||||||
|
end
|
||||||
|
|
||||||
elseif typeof(z) <: AbstractVector
|
elseif typeof(z) <: AbstractVector
|
||||||
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
|
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
|
||||||
handle = ax[:plot_trisurf](x, y, z;
|
handle = ax[:plot_trisurf](x, y, z;
|
||||||
|
|||||||
@ -8,6 +8,14 @@ abstract AbstractBackend
|
|||||||
abstract AbstractPlot{T<:AbstractBackend}
|
abstract AbstractPlot{T<:AbstractBackend}
|
||||||
|
|
||||||
typealias KW Dict{Symbol,Any}
|
typealias KW Dict{Symbol,Any}
|
||||||
|
|
||||||
|
immutable InputWrapper{T}
|
||||||
|
obj::T
|
||||||
|
end
|
||||||
|
|
||||||
|
wrap{T}(obj::T) = InputWrapper{T}(obj)
|
||||||
|
Base.isempty(wrapper::InputWrapper) = false
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# Plot
|
# Plot
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user