InputWrapper and pyplot surface zcolor

This commit is contained in:
Thomas Breloff 2016-04-28 22:03:52 -04:00
parent db118d4f5a
commit 005ce11313
4 changed files with 36 additions and 4 deletions

View File

@ -20,6 +20,8 @@ export
AVec,
AMat,
KW,
wrap,
set_theme,
add_theme,

View File

@ -754,19 +754,21 @@ end
# 1-row matrices will give an element
# multi-row matrices will give a column
# InputWrapper just gives the contents
# anything else is returned as-is
# getArgValue(v::Tuple, idx::Int) = v[mod1(idx, length(v))]
function getArgValue(v::AMat, idx::Int)
c = mod1(idx, size(v,2))
size(v,1) == 1 ? v[1,c] : v[:,c]
end
getArgValue(wrapper::InputWrapper, idx) = wrapper.obj
getArgValue(v, idx) = v
# 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.
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)
else
d_out[k] = defaults[k]

View File

@ -11,7 +11,8 @@ function _initialize_backend(::PyPlotBackend)
const pypatches = PyPlot.pywrap(PyPlot.pyimport("matplotlib.patches"))
const pyfont = PyPlot.pywrap(PyPlot.pyimport("matplotlib.font_manager"))
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
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
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)
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
linetype == :none && return " "
@ -508,8 +518,13 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
z = z'
end
if lt == :surface
extrakw[:cmap] = pyfillcolormap(d)
needs_colorbar = true
if d[:marker_z] != nothing
extrakw[:facecolors] = getPyPlotCustomShading(d[:fillcolor], d[:marker_z], d[:fillalpha])
extrakw[:shade] = false
else
extrakw[:cmap] = pyfillcolormap(d)
needs_colorbar = true
end
end
handle = ax[lt == :surface ? :plot_surface : :plot_wireframe](x, y, z;
label = d[:label],
@ -536,6 +551,11 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
end
end
# no colorbar if we are creating a surface LightSource
if haskey(extrakw, :facecolors)
needs_colorbar = false
end
elseif typeof(z) <: AbstractVector
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
handle = ax[:plot_trisurf](x, y, z;

View File

@ -8,6 +8,14 @@ abstract AbstractBackend
abstract AbstractPlot{T<:AbstractBackend}
typealias KW Dict{Symbol,Any}
immutable InputWrapper{T}
obj::T
end
wrap{T}(obj::T) = InputWrapper{T}(obj)
Base.isempty(wrapper::InputWrapper) = false
# -----------------------------------------------------------
# Plot
# -----------------------------------------------------------