Add support for levels keyword in PyPlot

This commit is contained in:
Sheehan Olver 2015-12-29 15:32:49 +11:00
parent ed7cc9b89e
commit c09545de64
3 changed files with 25 additions and 16 deletions

View File

@ -2,8 +2,8 @@
const _allAxes = [:auto, :left, :right] const _allAxes = [:auto, :left, :right]
@compat const _axesAliases = Dict( @compat const _axesAliases = Dict(
:a => :auto, :a => :auto,
:l => :left, :l => :left,
:r => :right :r => :right
) )
@ -139,6 +139,7 @@ _seriesDefaults[:z] = nothing # depth for contour, surfa
_seriesDefaults[:zcolor] = nothing # value for color scale _seriesDefaults[:zcolor] = nothing # value for color scale
# _seriesDefaults[:surface] = nothing # _seriesDefaults[:surface] = nothing
_seriesDefaults[:nlevels] = 15 _seriesDefaults[:nlevels] = 15
_seriesDefaults[:levels] = nothing
_seriesDefaults[:orientation] = :vertical _seriesDefaults[:orientation] = :vertical
@ -407,7 +408,7 @@ function processLineArg(d::Dict, arg)
# linetype # linetype
if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg) if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg)
d[:linetype] = arg d[:linetype] = arg
# linestyle # linestyle
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg) elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
d[:linestyle] = arg d[:linestyle] = arg
@ -446,7 +447,7 @@ function processMarkerArg(d::Dict, arg)
d[:markershape] = arg d[:markershape] = arg
elseif trueOrAllTrue(a -> isa(a, Shape), arg) elseif trueOrAllTrue(a -> isa(a, Shape), arg)
d[:markershape] = arg d[:markershape] = arg
# stroke style # stroke style
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg) elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
d[:markerstrokestyle] = arg d[:markerstrokestyle] = arg
@ -473,7 +474,7 @@ function processMarkerArg(d::Dict, arg)
# markercolor # markercolor
elseif !handleColors!(d, arg, :markercolor) elseif !handleColors!(d, arg, :markercolor)
warn("Skipped marker arg $arg.") warn("Skipped marker arg $arg.")
end end
end end
@ -493,7 +494,7 @@ end
"Handle all preprocessing of args... break out colors/sizes/etc and replace aliases." "Handle all preprocessing of args... break out colors/sizes/etc and replace aliases."
function preprocessArgs!(d::Dict) function preprocessArgs!(d::Dict)
replaceAliases!(d, _keyAliases) replaceAliases!(d, _keyAliases)
# handle axis args # handle axis args
for axisletter in ("x", "y") for axisletter in ("x", "y")
asym = symbol(axisletter * "axis") asym = symbol(axisletter * "axis")
@ -590,7 +591,7 @@ end
function warnOnUnsupported(pkg::PlottingPackage, d::Dict) function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
(d[:axis] in supportedAxes(pkg) (d[:axis] in supportedAxes(pkg)
|| warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))")) || warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))"))
(d[:linetype] == :none (d[:linetype] == :none
|| d[:linetype] in supportedTypes(pkg) || d[:linetype] in supportedTypes(pkg)
@ -683,7 +684,7 @@ function getSeriesArgs(pkg::PlottingPackage, plotargs::Dict, kw, commandIndex::I
d[k] = kwdict[k] d[k] = kwdict[k]
end end
end end
if haskey(_typeAliases, d[:linetype]) if haskey(_typeAliases, d[:linetype])
d[:linetype] = _typeAliases[d[:linetype]] d[:linetype] = _typeAliases[d[:linetype]]
end end

View File

@ -232,7 +232,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
if lt == :sticks if lt == :sticks
d,_ = sticksHack(;d...) d,_ = sticksHack(;d...)
elseif lt in (:scatter, :scatter3d) elseif lt in (:scatter, :scatter3d)
if d[:markershape] == :none if d[:markershape] == :none
d[:markershape] = :ellipse d[:markershape] = :ellipse
@ -334,13 +334,20 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
d[:serieshandle] = if ishistlike(lt) d[:serieshandle] = if ishistlike(lt)
plotfunc(d[:y]; extra_kwargs...)[1] plotfunc(d[:y]; extra_kwargs...)[1]
elseif lt == :contour elseif lt == :contour
# NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed), # NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed),
# and take the transpose of the surface matrix # and take the transpose of the surface matrix
x, y = d[:x], d[:y] x, y = d[:x], d[:y]
surf = d[:z].surf' surf = d[:z].surf'
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...) if d[:levels] != nothing
if d[:fillrange] != nothing handle = plotfunc(x, y, surf; levels=d[:levels], extra_kwargs...)
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])) if d[:fillrange] != nothing
handle = ax[:contourf](x, y, surf; levels=d[:levels], cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
end
else
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...)
if d[:fillrange] != nothing
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
end
end end
handle handle
elseif lt in (:surface,:wireframe) elseif lt in (:surface,:wireframe)
@ -473,7 +480,7 @@ function _update_plot(plt::Plot{PyPlotPackage}, d::Dict)
ax[:set_ylabel](d[:ylabel]) ax[:set_ylabel](d[:ylabel])
end end
if usingRightAxis(plt) && get(d, :yrightlabel, "") != "" if usingRightAxis(plt) && get(d, :yrightlabel, "") != ""
rightax = getRightAxis(figorax) rightax = getRightAxis(figorax)
rightax[:set_ylabel](d[:yrightlabel]) rightax[:set_ylabel](d[:yrightlabel])
end end
@ -502,7 +509,7 @@ function _update_plot(plt::Plot{PyPlotPackage}, d::Dict)
# font sizes # font sizes
for ax in axes for ax in axes
# haskey(d, :yrightlabel) || continue # haskey(d, :yrightlabel) || continue
# guides # guides
sz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize sz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
@ -517,7 +524,7 @@ function _update_plot(plt::Plot{PyPlotPackage}, d::Dict)
lab[:set_fontsize](sz) lab[:set_fontsize](sz)
end end
end end
# grid # grid
if get(d, :grid, false) if get(d, :grid, false)
ax[:xaxis][:grid](true) ax[:xaxis][:grid](true)

View File

@ -155,6 +155,7 @@ supportedArgs(::PyPlotPackage) = [
:grid, :grid,
# :surface, # :surface,
:nlevels, :nlevels,
:levels,
:fillalpha, :fillalpha,
:linealpha, :linealpha,
:markeralpha, :markeralpha,