contours keyword for surface and wireframe plots

This commit is contained in:
Thomas Breloff 2016-04-26 15:09:18 -04:00
parent 8b569e3cd8
commit 8d6974f67d
3 changed files with 39 additions and 23 deletions

View File

@ -147,6 +147,7 @@ _seriesDefaults[:ribbon] = nothing
_seriesDefaults[:quiver] = nothing _seriesDefaults[:quiver] = nothing
_seriesDefaults[:normalize] = false # do we want a normalized histogram? _seriesDefaults[:normalize] = false # do we want a normalized histogram?
_seriesDefaults[:weights] = nothing # optional weights for histograms (1D and 2D) _seriesDefaults[:weights] = nothing # optional weights for histograms (1D and 2D)
_seriesDefaults[:contours] = false # add contours to 3d surface and wireframe plots
const _plotDefaults = KW() const _plotDefaults = KW()

View File

@ -327,6 +327,18 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
needs_colorbar = false needs_colorbar = false
discrete_colorbar_values = nothing discrete_colorbar_values = nothing
# pass in an integer value as an arg, but a levels list as a keyword arg
levels = d[:levels]
levelargs = if isscalar(levels)
(levels)
elseif isvector(levels)
extrakw[:levels] = levels
()
else
error("Only numbers and vectors are supported with levels keyword")
end
# for each plotting command, optionally build and add a series handle to the list # for each plotting command, optionally build and add a series handle to the list
# line plot # line plot
@ -459,23 +471,13 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
z = z.surf' z = z.surf'
needs_colorbar = true needs_colorbar = true
# pass in an integer value as an arg, but a levels list as a keyword arg
levels = d[:levels]
args = if isscalar(levels)
(levels)
elseif isvector(levels)
extrakw[:levels] = levels
()
else
error("Only numbers and vectors are supported with levels keyword")
end
if lt == :contour3d if lt == :contour3d
extrakw[:extend3d] = true extrakw[:extend3d] = true
end end
# contour lines # contour lines
handle = ax[:contour](x, y, z, args...; handle = ax[:contour](x, y, z, levelargs...;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = plt.n,
linewidths = d[:linewidth], linewidths = d[:linewidth],
@ -486,19 +488,19 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
push!(handles, handle) push!(handles, handle)
# contour fills # contour fills
if lt == :contour # if lt == :contour
handle = ax[:contourf](x, y, z, args...; handle = ax[:contourf](x, y, z, levelargs...;
label = d[:label], label = d[:label],
zorder = plt.n + 0.5, zorder = plt.n + 0.5,
cmap = pyfillcolormap(d), cmap = pyfillcolormap(d),
extrakw... extrakw...
) )
push!(handles, handle) push!(handles, handle)
end # end
end end
if lt in (:surface, :wireframe) if lt in (:surface, :wireframe)
if typeof(z) <: AbstractMatrix if typeof(z) <: AbstractMatrix || typeof(z) <: Surface
x, y, z = map(Array, (x,y,z)) x, y, z = map(Array, (x,y,z))
if !ismatrix(x) || !ismatrix(y) if !ismatrix(x) || !ismatrix(y)
x = repmat(x', length(y), 1) x = repmat(x', length(y), 1)
@ -520,6 +522,20 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
) )
push!(handles, handle) push!(handles, handle)
# contours on the axis planes
if d[:contours]
for (zdir,mat) in (("x",x), ("y",y), ("z",z))
offset = (zdir == "y" ? maximum : minimum)(mat)
handle = ax[:contourf](x, y, z, levelargs...;
zdir = zdir,
cmap = pyfillcolormap(d),
offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane
)
push!(handles, handle)
needs_colorbar = true
end
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;
@ -534,7 +550,6 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
else else
error("Unsupported z type $(typeof(z)) for linetype=$lt") error("Unsupported z type $(typeof(z)) for linetype=$lt")
end end
end end
if lt == :heatmap if lt == :heatmap

View File

@ -104,7 +104,7 @@ supportedArgs(::PyPlotBackend) = [
:orientation, :orientation,
:overwrite_figure, :overwrite_figure,
:polar, :polar,
:normalize, :weights :normalize, :weights, :contours
] ]
supportedAxes(::PyPlotBackend) = _allAxes supportedAxes(::PyPlotBackend) = _allAxes
supportedTypes(::PyPlotBackend) = [ supportedTypes(::PyPlotBackend) = [