z axis args; pyplot z axis; major pyplot cleanup; other cleanup/fixes
This commit is contained in:
parent
0a636b5899
commit
d70f462899
60
src/args.jl
60
src/args.jl
@ -159,6 +159,7 @@ const _plotDefaults = KW()
|
||||
_plotDefaults[:title] = ""
|
||||
_plotDefaults[:xlabel] = ""
|
||||
_plotDefaults[:ylabel] = ""
|
||||
_plotDefaults[:zlabel] = ""
|
||||
_plotDefaults[:yrightlabel] = ""
|
||||
_plotDefaults[:legend] = :best
|
||||
_plotDefaults[:colorbar] = :legend
|
||||
@ -169,10 +170,13 @@ _plotDefaults[:ylims] = :auto
|
||||
_plotDefaults[:zlims] = :auto
|
||||
_plotDefaults[:xticks] = :auto
|
||||
_plotDefaults[:yticks] = :auto
|
||||
_plotDefaults[:zticks] = :auto
|
||||
_plotDefaults[:xscale] = :identity
|
||||
_plotDefaults[:yscale] = :identity
|
||||
_plotDefaults[:zscale] = :identity
|
||||
_plotDefaults[:xflip] = false
|
||||
_plotDefaults[:yflip] = false
|
||||
_plotDefaults[:zflip] = false
|
||||
_plotDefaults[:size] = (600,400)
|
||||
_plotDefaults[:pos] = (0,0)
|
||||
_plotDefaults[:windowtitle] = "Plots.jl"
|
||||
@ -222,7 +226,6 @@ function aliasesAndAutopick(d::KW, sym::Symbol, aliases::KW, options::AVec, plot
|
||||
end
|
||||
|
||||
function aliases(aliasMap::KW, val)
|
||||
# sort(vcat(val, collect(keys(filter((k,v)-> v==val, aliasMap)))))
|
||||
sortedkeys(filter((k,v)-> v==val, aliasMap))
|
||||
end
|
||||
|
||||
@ -278,6 +281,7 @@ end
|
||||
:annotations => :annotation,
|
||||
:xlab => :xlabel,
|
||||
:ylab => :ylabel,
|
||||
:zlab => :zlabel,
|
||||
:yrlab => :yrightlabel,
|
||||
:ylabr => :yrightlabel,
|
||||
:y2lab => :yrightlabel,
|
||||
@ -404,48 +408,47 @@ end
|
||||
|
||||
# given one value (:log, or :flip, or (-1,1), etc), set the appropriate arg
|
||||
# TODO: use trueOrAllTrue for subplots which can pass vectors for these
|
||||
function processAxisArg(d::KW, axisletter::@compat(AbstractString), arg)
|
||||
function processAxisArg(d::KW, letter::AbstractString, arg)
|
||||
T = typeof(arg)
|
||||
# if T <: Symbol
|
||||
|
||||
arg = get(_scaleAliases, arg, arg)
|
||||
scale, flip, label, lim, tick = axis_symbols(letter, "scale", "flip", "label", "lims", "ticks")
|
||||
|
||||
if arg in _allScales
|
||||
d[symbol(axisletter * "scale")] = arg
|
||||
if typeof(arg) <: Font
|
||||
d[:tickfont] = arg
|
||||
|
||||
elseif arg in _allScales
|
||||
d[scale] = arg
|
||||
|
||||
elseif arg in (:flip, :invert, :inverted)
|
||||
d[symbol(axisletter * "flip")] = true
|
||||
d[flip] = true
|
||||
|
||||
elseif T <: @compat(AbstractString)
|
||||
d[symbol(axisletter * "label")] = arg
|
||||
d[label] = arg
|
||||
|
||||
# xlims/ylims
|
||||
elseif (T <: Tuple || T <: AVec) && length(arg) == 2
|
||||
d[symbol(axisletter * "lims")] = arg
|
||||
d[typeof(arg[1]) <: Number ? lim : tick] = arg
|
||||
|
||||
# xticks/yticks
|
||||
elseif T <: AVec
|
||||
d[symbol(axisletter * "ticks")] = arg
|
||||
d[tick] = arg
|
||||
|
||||
elseif arg == nothing
|
||||
d[symbol(axisletter * "ticks")] = []
|
||||
d[tick] = []
|
||||
|
||||
else
|
||||
warn("Skipped $(axisletter)axis arg $arg")
|
||||
warn("Skipped $(letter)axis arg $arg")
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function processLineArg(d::KW, arg)
|
||||
|
||||
# linetype
|
||||
# if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg)
|
||||
if allLineTypes(arg)
|
||||
d[:linetype] = arg
|
||||
|
||||
# linestyle
|
||||
# elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
|
||||
elseif allStyles(arg)
|
||||
d[:linestyle] = arg
|
||||
|
||||
@ -461,12 +464,10 @@ function processLineArg(d::KW, arg)
|
||||
arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
|
||||
|
||||
# linealpha
|
||||
# elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
|
||||
elseif allAlphas(arg)
|
||||
d[:linealpha] = arg
|
||||
|
||||
# linewidth
|
||||
# elseif trueOrAllTrue(a -> typeof(a) <: Real, arg)
|
||||
elseif allReals(arg)
|
||||
d[:linewidth] = arg
|
||||
|
||||
@ -479,17 +480,11 @@ end
|
||||
|
||||
|
||||
function processMarkerArg(d::KW, arg)
|
||||
|
||||
# markershape
|
||||
# if trueOrAllTrue(a -> get(_markerAliases, a, a) in _allMarkers, arg)
|
||||
# d[:markershape] = arg
|
||||
|
||||
# elseif trueOrAllTrue(a -> isa(a, Shape), arg)
|
||||
if allShapes(arg)
|
||||
d[:markershape] = arg
|
||||
|
||||
# stroke style
|
||||
# elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
|
||||
elseif allStyles(arg)
|
||||
d[:markerstrokestyle] = arg
|
||||
|
||||
@ -505,12 +500,10 @@ function processMarkerArg(d::KW, arg)
|
||||
arg.alpha == nothing || (d[:markeralpha] = arg.alpha)
|
||||
|
||||
# linealpha
|
||||
# elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
|
||||
elseif allAlphas(arg)
|
||||
d[:markeralpha] = arg
|
||||
|
||||
# markersize
|
||||
# elseif trueOrAllTrue(a -> typeof(a) <: Real, arg)
|
||||
elseif allReals(arg)
|
||||
d[:markersize] = arg
|
||||
|
||||
@ -523,19 +516,16 @@ end
|
||||
|
||||
|
||||
function processFillArg(d::KW, arg)
|
||||
|
||||
if typeof(arg) <: Brush
|
||||
arg.size == nothing || (d[:fillrange] = arg.size)
|
||||
arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : colorscheme(arg.color))
|
||||
arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
|
||||
|
||||
# fillrange function
|
||||
# elseif trueOrAllTrue(a -> isa(a, Function), arg)
|
||||
elseif allFunctions(arg)
|
||||
d[:fillrange] = arg
|
||||
|
||||
# fillalpha
|
||||
# elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
|
||||
elseif allAlphas(arg)
|
||||
d[:fillalpha] = arg
|
||||
|
||||
@ -555,15 +545,15 @@ function preprocessArgs!(d::KW)
|
||||
replaceAliases!(d, _keyAliases)
|
||||
|
||||
# handle axis args
|
||||
for axisletter in ("x", "y")
|
||||
asym = symbol(axisletter * "axis")
|
||||
for letter in ("x", "y", "z")
|
||||
asym = symbol(letter * "axis")
|
||||
for arg in wraptuple(get(d, asym, ()))
|
||||
processAxisArg(d, axisletter, arg)
|
||||
processAxisArg(d, letter, arg)
|
||||
end
|
||||
delete!(d, asym)
|
||||
|
||||
# turn :labels into :ticks_and_labels
|
||||
tsym = symbol(axisletter * "ticks")
|
||||
tsym = symbol(letter * "ticks")
|
||||
if haskey(d, tsym) && ticksType(d[tsym]) == :labels
|
||||
d[tsym] = (1:length(d[tsym]), d[tsym])
|
||||
end
|
||||
@ -582,9 +572,6 @@ function preprocessArgs!(d::KW)
|
||||
anymarker = true
|
||||
end
|
||||
delete!(d, :marker)
|
||||
# if anymarker && !haskey(d, :markershape)
|
||||
# d[:markershape] = :ellipse
|
||||
# end
|
||||
if haskey(d, :markershape)
|
||||
d[:markershape] = _replace_markershape(d[:markershape])
|
||||
elseif anymarker
|
||||
@ -681,8 +668,6 @@ function warnOnUnsupported(pkg::AbstractBackend, d::KW)
|
||||
|| warn("linestyle $(d[:linestyle]) is unsupported with $pkg. Choose from: $(supportedStyles(pkg))"))
|
||||
(d[:markershape] == :none
|
||||
|| _markershape_supported(pkg, d[:markershape])
|
||||
# || d[:markershape] in supportedMarkers(pkg)
|
||||
# || (Shape in supportedMarkers(pkg) && typeof(d[:markershape]) <: Shape)
|
||||
|| warn("markershape $(d[:markershape]) is unsupported with $pkg. Choose from: $(supportedMarkers(pkg))"))
|
||||
end
|
||||
|
||||
@ -823,6 +808,5 @@ function getSeriesArgs(pkg::AbstractBackend, plotargs::KW, kw, commandIndex::Int
|
||||
|
||||
warnOnUnsupported(pkg, d)
|
||||
|
||||
|
||||
d
|
||||
end
|
||||
|
||||
@ -35,14 +35,9 @@ getPyPlotColor(c::Colorant, α=nothing) = map(f->float(f(convertColor(c,α))), (
|
||||
getPyPlotColor(cvec::ColorVector, α=nothing) = map(getPyPlotColor, convertColor(cvec, α).v)
|
||||
getPyPlotColor(scheme::ColorScheme, α=nothing) = getPyPlotColor(convertColor(getColor(scheme), α))
|
||||
getPyPlotColor(c, α=nothing) = getPyPlotColor(convertColor(c, α))
|
||||
# getPyPlotColor(c, alpha) = getPyPlotColor(colorscheme(c, alpha))
|
||||
|
||||
function getPyPlotColorMap(c::ColorGradient, α=nothing)
|
||||
# c = ColorGradient(c.colors, c.values, alpha=α)
|
||||
# pycolors.pymember("LinearSegmentedColormap")[:from_list]("tmp", map(getPyPlotColor, getColorVector(c)))
|
||||
# pyvals = [(c.values[i], getPyPlotColor(c.colors[i], α)) for i in 1:length(c.colors)]
|
||||
pyvals = [(v, getPyPlotColor(getColorZ(c, v), α)) for v in c.values]
|
||||
# @show c α pyvals
|
||||
pycolors.pymember("LinearSegmentedColormap")[:from_list]("tmp", pyvals)
|
||||
end
|
||||
|
||||
@ -69,7 +64,6 @@ function getPyPlotMarker(marker::Shape)
|
||||
end
|
||||
mat[n+1,:] = mat[1,:]
|
||||
pypath.pymember("Path")(mat)
|
||||
# marker.vertices
|
||||
end
|
||||
|
||||
const _path_MOVETO = UInt8(1)
|
||||
@ -135,11 +129,7 @@ function getPyPlotStepStyle(linetype::Symbol)
|
||||
return "default"
|
||||
end
|
||||
|
||||
|
||||
# immutable PyPlotFigWrapper
|
||||
# fig
|
||||
# kwargs # for add_subplot
|
||||
# end
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
type PyPlotAxisWrapper
|
||||
ax
|
||||
@ -148,7 +138,6 @@ type PyPlotAxisWrapper
|
||||
kwargs # for add_subplot
|
||||
end
|
||||
|
||||
# getfig(wrap::@compat(Union{PyPlotAxisWrapper,PyPlotFigWrapper})) = wrap.fig
|
||||
getfig(wrap::PyPlotAxisWrapper) = wrap.fig
|
||||
|
||||
|
||||
@ -165,8 +154,6 @@ function getLeftAxis(wrap::PyPlotAxisWrapper)
|
||||
wrap.ax
|
||||
end
|
||||
end
|
||||
# getLeftAxis(wrap::PyPlotAxisWrapper) = wrap.ax
|
||||
# getRightAxis(x) = getLeftAxis(x)[:twinx]()
|
||||
|
||||
function getRightAxis(wrap::PyPlotAxisWrapper)
|
||||
if wrap.rightax == nothing
|
||||
@ -209,21 +196,6 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
||||
return ax[get(fmap, linetype, :plot)]
|
||||
end
|
||||
|
||||
function updateAxisColors(ax, fgcolor)
|
||||
# for loc in ("bottom", "top", "left", "right")
|
||||
for (loc, spine) in ax[:spines]
|
||||
# ax[:spines][loc][:set_color](fgcolor)
|
||||
spine[:set_color](fgcolor)
|
||||
end
|
||||
for axis in ("x", "y")
|
||||
ax[:tick_params](axis=axis, colors=fgcolor, which="both")
|
||||
end
|
||||
for axis in (:yaxis, :xaxis)
|
||||
ax[axis][:label][:set_color](fgcolor)
|
||||
end
|
||||
ax[:title][:set_color](fgcolor)
|
||||
end
|
||||
|
||||
|
||||
function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Bool)
|
||||
if smooth
|
||||
@ -237,11 +209,8 @@ function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Bool)
|
||||
end
|
||||
handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Real) = handleSmooth(plt, ax, d, true)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
# makePyPlotCurrent(wrap::PyPlotFigWrapper) = PyPlot.figure(wrap.fig.o[:number])
|
||||
# makePyPlotCurrent(wrap::PyPlotAxisWrapper) = nothing #PyPlot.sca(wrap.ax.o)
|
||||
makePyPlotCurrent(wrap::PyPlotAxisWrapper) = wrap.ax == nothing ? PyPlot.figure(wrap.fig.o[:number]) : nothing
|
||||
makePyPlotCurrent(plt::Plot{PyPlotBackend}) = plt.o == nothing ? nothing : makePyPlotCurrent(plt.o)
|
||||
|
||||
@ -287,14 +256,7 @@ function pyplot_3d_setup!(wrap, d)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# TODO:
|
||||
# fillto # might have to use barHack/histogramHack??
|
||||
# reg # true or false, add a regression line for each line
|
||||
# pos # (Int,Int), move the enclosing window to this position
|
||||
# windowtitle # string or symbol, set the title of the enclosing windowtitle
|
||||
# screen # Integer, move enclosing window to this screen number (for multiscreen desktops)
|
||||
# show # true or false, show the plot (in case you don't want the window to pop up right away)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
function _create_plot(pkg::PyPlotBackend; kw...)
|
||||
# create the figure
|
||||
@ -321,6 +283,7 @@ function _create_plot(pkg::PyPlotBackend; kw...)
|
||||
plt
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
function _add_series(pkg::PyPlotBackend, plt::Plot; kw...)
|
||||
d = KW(kw)
|
||||
@ -430,7 +393,6 @@ function _add_series(pkg::PyPlotBackend, plt::Plot; kw...)
|
||||
extra_kwargs[:c] = convert(Vector{Float64}, d[:zcolor])
|
||||
extra_kwargs[:cmap] = getPyPlotColorMap(c, d[:markeralpha])
|
||||
else
|
||||
# extra_kwargs[:c] = getPyPlotColor(c, d[:markeralpha])
|
||||
ppc = getPyPlotColor(c, d[:markeralpha])
|
||||
|
||||
# total hack due to PyPlot bug (see issue #145).
|
||||
@ -442,9 +404,6 @@ function _add_series(pkg::PyPlotBackend, plt::Plot; kw...)
|
||||
extra_kwargs[:c] = ppc
|
||||
|
||||
end
|
||||
# if d[:markeralpha] != nothing
|
||||
# extra_kwargs[:alpha] = d[:markeralpha]
|
||||
# end
|
||||
extra_kwargs[:edgecolors] = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha])
|
||||
extra_kwargs[:linewidths] = d[:markerstrokewidth]
|
||||
else
|
||||
@ -456,12 +415,6 @@ function _add_series(pkg::PyPlotBackend, plt::Plot; kw...)
|
||||
end
|
||||
end
|
||||
|
||||
# if d[:markeralpha] != nothing
|
||||
# extra_kwargs[:alpha] = d[:markeralpha]
|
||||
# elseif d[:linealpha] != nothing
|
||||
# extra_kwargs[:alpha] = d[:linealpha]
|
||||
# end
|
||||
|
||||
# set these for all types
|
||||
if !(lt in (:contour,:surface,:wireframe,:heatmap))
|
||||
if !(lt in (:scatter, :scatter3d, :shape))
|
||||
@ -619,120 +572,46 @@ function Base.setindex!{X,Y,Z}(plt::Plot{PyPlotBackend}, xyz::Tuple{X,Y,Z}, i::I
|
||||
plt
|
||||
end
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
function addPyPlotLims(ax, lims, dimension)
|
||||
function addPyPlotLims(ax, lims, letter)
|
||||
lims == :auto && return
|
||||
ltype = limsType(lims)
|
||||
if ltype == :limits
|
||||
if dimension == :xlim
|
||||
isfinite(lims[1]) && ax[:set_xlim](left = lims[1])
|
||||
isfinite(lims[2]) && ax[:set_xlim](right = lims[2])
|
||||
elseif dimension == :ylim
|
||||
isfinite(lims[1]) && ax[:set_ylim](bottom = lims[1])
|
||||
isfinite(lims[2]) && ax[:set_ylim](top = lims[2])
|
||||
elseif dimension == :zlim && haskey(ax, :set_zlim)
|
||||
isfinite(lims[1]) && ax[:set_zlim](bottom = lims[1])
|
||||
isfinite(lims[2]) && ax[:set_zlim](top = lims[2])
|
||||
else
|
||||
error("Invalid argument at position 3: $dimension")
|
||||
setf = ax[symbol("set_", letter, "lim")]
|
||||
l1, l2 = lims
|
||||
if isfinite(l1)
|
||||
letter == "x" ? setf(left = l1) : setf(bottom = l1)
|
||||
end
|
||||
if isfinite(l2)
|
||||
letter == "x" ? setf(right = l2) : setf(top = l2)
|
||||
end
|
||||
else
|
||||
error("Invalid input for $dimension: ", lims)
|
||||
error("Invalid input for $letter: ", lims)
|
||||
end
|
||||
end
|
||||
|
||||
function addPyPlotTicks(ax, ticks, isx::Bool)
|
||||
function addPyPlotTicks(ax, ticks, letter)
|
||||
ticks == :auto && return
|
||||
if ticks == :none || ticks == nothing
|
||||
ticks = zeros(0)
|
||||
end
|
||||
|
||||
ttype = ticksType(ticks)
|
||||
tickfunc = symbol("set_", letter, "ticks")
|
||||
labfunc = symbol("set_", letter, "ticklabels")
|
||||
if ttype == :ticks
|
||||
ax[isx ? :set_xticks : :set_yticks](ticks)
|
||||
ax[tickfunc](ticks)
|
||||
elseif ttype == :ticks_and_labels
|
||||
ax[isx ? :set_xticks : :set_yticks](ticks[1])
|
||||
ax[isx ? :set_xticklabels : :set_yticklabels](ticks[2])
|
||||
ax[tickfunc](ticks[1])
|
||||
ax[labfunc](ticks[2])
|
||||
else
|
||||
error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks)
|
||||
end
|
||||
end
|
||||
|
||||
usingRightAxis(plt::Plot{PyPlotBackend}) = any(args -> args[:axis] in (:right,:auto), plt.seriesargs)
|
||||
|
||||
function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
||||
figorax = plt.o
|
||||
ax = getLeftAxis(figorax)
|
||||
# PyPlot.sca(ax)
|
||||
|
||||
|
||||
# title and axis labels
|
||||
# haskey(d, :title) && PyPlot.title(d[:title])
|
||||
haskey(d, :title) && ax[:set_title](d[:title])
|
||||
haskey(d, :xlabel) && ax[:set_xlabel](d[:xlabel])
|
||||
if haskey(d, :ylabel)
|
||||
ax[:set_ylabel](d[:ylabel])
|
||||
end
|
||||
if usingRightAxis(plt) && get(d, :yrightlabel, "") != ""
|
||||
rightax = getRightAxis(figorax)
|
||||
rightax[:set_ylabel](d[:yrightlabel])
|
||||
end
|
||||
|
||||
# scales
|
||||
haskey(d, :xscale) && applyPyPlotScale(ax, d[:xscale], true)
|
||||
haskey(d, :yscale) && applyPyPlotScale(ax, d[:yscale], false)
|
||||
|
||||
# limits and ticks
|
||||
haskey(d, :xlims) && addPyPlotLims(ax, d[:xlims], :xlim)
|
||||
haskey(d, :ylims) && addPyPlotLims(ax, d[:ylims], :ylim)
|
||||
haskey(d, :zlims) && addPyPlotLims(ax, d[:zlims], :zlim)
|
||||
haskey(d, :xticks) && addPyPlotTicks(ax, d[:xticks], true)
|
||||
haskey(d, :yticks) && addPyPlotTicks(ax, d[:yticks], false)
|
||||
|
||||
if get(d, :xflip, false)
|
||||
ax[:invert_xaxis]()
|
||||
end
|
||||
if get(d, :yflip, false)
|
||||
ax[:invert_yaxis]()
|
||||
end
|
||||
|
||||
axes = [getLeftAxis(figorax)]
|
||||
if usingRightAxis(plt)
|
||||
push!(axes, getRightAxis(figorax))
|
||||
end
|
||||
|
||||
# font sizes
|
||||
for ax in axes
|
||||
# haskey(d, :yrightlabel) || continue
|
||||
|
||||
|
||||
# guides
|
||||
sz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
|
||||
ax[:title][:set_fontsize](sz)
|
||||
ax[:xaxis][:label][:set_fontsize](sz)
|
||||
ax[:yaxis][:label][:set_fontsize](sz)
|
||||
|
||||
# ticks
|
||||
sz = get(d, :tickfont, plt.plotargs[:tickfont]).pointsize
|
||||
for sym in (:get_xticklabels, :get_yticklabels)
|
||||
for lab in ax[sym]()
|
||||
lab[:set_fontsize](sz)
|
||||
end
|
||||
end
|
||||
|
||||
# grid
|
||||
if get(d, :grid, false)
|
||||
ax[:xaxis][:grid](true)
|
||||
ax[:yaxis][:grid](true)
|
||||
ax[:set_axisbelow](true)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function applyPyPlotScale(ax, scaleType::Symbol, isx::Bool)
|
||||
func = ax[isx ? :set_xscale : :set_yscale]
|
||||
function applyPyPlotScale(ax, scaleType::Symbol, letter)
|
||||
func = ax[symbol("set_", letter, "scale")]
|
||||
scaleType == :identity && return func("linear")
|
||||
scaleType == :ln && return func("log", basex = e, basey = e)
|
||||
scaleType == :log2 && return func("log", basex = 2, basey = 2)
|
||||
@ -740,6 +619,75 @@ function applyPyPlotScale(ax, scaleType::Symbol, isx::Bool)
|
||||
warn("Unhandled scaleType: ", scaleType)
|
||||
end
|
||||
|
||||
|
||||
function updateAxisColors(ax, fgcolor)
|
||||
for (loc, spine) in ax[:spines]
|
||||
spine[:set_color](fgcolor)
|
||||
end
|
||||
for letter in ("x", "y", "z")
|
||||
axis = axis_symbol(letter, "axis")
|
||||
if haskey(ax, axis)
|
||||
ax[:tick_params](axis=letter, colors=fgcolor, which="both")
|
||||
ax[axis][:label][:set_color](fgcolor)
|
||||
end
|
||||
end
|
||||
ax[:title][:set_color](fgcolor)
|
||||
end
|
||||
|
||||
function usingRightAxis(plt::Plot{PyPlotBackend})
|
||||
any(args -> args[:axis] in (:right,:auto), plt.seriesargs)
|
||||
end
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
||||
figorax = plt.o
|
||||
ax = getLeftAxis(figorax)
|
||||
ticksz = get(d, :tickfont, plt.plotargs[:tickfont]).pointsize
|
||||
guidesz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
|
||||
|
||||
# title
|
||||
haskey(d, :title) && ax[:set_title](d[:title])
|
||||
ax[:title][:set_fontsize](guidesz)
|
||||
|
||||
# handle right y axis
|
||||
axes = [getLeftAxis(figorax)]
|
||||
if usingRightAxis(plt)
|
||||
push!(axes, getRightAxis(figorax))
|
||||
if get(d, :yrightlabel, "") != ""
|
||||
rightax = getRightAxis(figorax)
|
||||
rightax[:set_ylabel](d[:yrightlabel])
|
||||
end
|
||||
end
|
||||
|
||||
# handle each axis in turn
|
||||
for letter in ("x", "y", "z")
|
||||
axis, scale, lims, ticks, flip, lab = axis_symbols(letter, "axis", "scale", "lims", "ticks", "flip", "label")
|
||||
haskey(ax, axis) || continue
|
||||
haskey(d, scale) && applyPyPlotScale(ax, d[scale], letter)
|
||||
haskey(d, lims) && addPyPlotLims(ax, d[lims], letter)
|
||||
haskey(d, ticks) && addPyPlotTicks(ax, d[ticks], letter)
|
||||
haskey(d, lab) && ax[symbol("set_", letter, "label")](d[lab])
|
||||
if get(d, flip, false)
|
||||
ax[symbol("invert_", letter, "axis")]()
|
||||
end
|
||||
for tmpax in axes
|
||||
tmpax[axis][:label][:set_fontsize](guidesz)
|
||||
for lab in tmpax[symbol("get_", letter, "ticklabels")]()
|
||||
lab[:set_fontsize](ticksz)
|
||||
end
|
||||
if get(d, :grid, false)
|
||||
fgcolor = getPyPlotColor(plt.plotargs[:foreground_color])
|
||||
tmpax[axis][:grid](true, color = fgcolor)
|
||||
tmpax[:set_axisbelow](true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::@compat(AbstractString))
|
||||
|
||||
@ -21,72 +21,36 @@ stringsSupported() = stringsSupported(backend())
|
||||
|
||||
supportedArgs(::GadflyBackend) = [
|
||||
:annotation,
|
||||
# :axis,
|
||||
:background_color,
|
||||
:linecolor,
|
||||
:color_palette,
|
||||
:fillrange,
|
||||
:fillcolor,
|
||||
:fillalpha,
|
||||
:foreground_color,
|
||||
:background_color, :foreground_color, :color_palette,
|
||||
:group,
|
||||
:label,
|
||||
:layout,
|
||||
:legend,
|
||||
:colorbar,
|
||||
:linestyle,
|
||||
:linetype,
|
||||
:linewidth,
|
||||
:linealpha,
|
||||
:markershape,
|
||||
:markercolor,
|
||||
:markersize,
|
||||
:markeralpha,
|
||||
:markerstrokewidth,
|
||||
:markerstrokecolor,
|
||||
:markerstrokealpha,
|
||||
# :markerstrokestyle,
|
||||
:n,
|
||||
:linecolor, :linestyle, :linewidth, :linealpha,
|
||||
:markershape, :markercolor, :markersize, :markeralpha,
|
||||
:markerstrokewidth, :markerstrokecolor, :markerstrokealpha,
|
||||
:fillrange, :fillcolor, :fillalpha,
|
||||
:nbins,
|
||||
:nc,
|
||||
:nr,
|
||||
# :pos,
|
||||
:n, :nc, :nr, :layout,
|
||||
:smooth,
|
||||
:show,
|
||||
:size,
|
||||
:title,
|
||||
:windowtitle,
|
||||
:x,
|
||||
:xlabel,
|
||||
:xlims,
|
||||
:xticks,
|
||||
:y,
|
||||
:ylabel,
|
||||
:ylims,
|
||||
# :yrightlabel,
|
||||
:yticks,
|
||||
:xscale,
|
||||
:yscale,
|
||||
:xflip,
|
||||
:yflip,
|
||||
:title, :windowtitle, :show, :size,
|
||||
:x, :xlabel, :xlims, :xticks, :xscale, :xflip,
|
||||
:y, :ylabel, :ylims, :yticks, :yscale, :yflip,
|
||||
# :z, :zlabel, :zlims, :zticks, :zscale, :zflip,
|
||||
:z,
|
||||
:zcolor,
|
||||
:tickfont,
|
||||
:guidefont,
|
||||
:legendfont,
|
||||
:grid,
|
||||
# :surface,
|
||||
:levels,
|
||||
:xerror,
|
||||
:yerror,
|
||||
:ribbon,
|
||||
:quiver,
|
||||
:tickfont, :guidefont, :legendfont,
|
||||
:grid, :legend, :colorbar,
|
||||
:zcolor, :levels,
|
||||
:xerror, :yerror,
|
||||
:ribbon, :quiver,
|
||||
:orientation,
|
||||
]
|
||||
supportedAxes(::GadflyBackend) = [:auto, :left]
|
||||
supportedTypes(::GadflyBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
||||
:scatter, :hist2d, :hexbin, :hist, :bar, :box, :violin, :quiver,
|
||||
:hline, :vline, :contour, :shape]
|
||||
supportedTypes(::GadflyBackend) = [
|
||||
:none, :line, :path, :steppre, :steppost, :sticks,
|
||||
:scatter, :hist2d, :hexbin, :hist,
|
||||
:bar, :box, :violin, :quiver,
|
||||
:hline, :vline, :contour, :shape
|
||||
]
|
||||
supportedStyles(::GadflyBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||
supportedMarkers(::GadflyBackend) = vcat(_allMarkers, Shape)
|
||||
supportedScales(::GadflyBackend) = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
|
||||
@ -110,78 +74,41 @@ subplotSupported(::ImmerseBackend) = true
|
||||
|
||||
supportedArgs(::PyPlotBackend) = [
|
||||
:annotation,
|
||||
:axis,
|
||||
:background_color,
|
||||
:linecolor,
|
||||
:color_palette,
|
||||
:fillrange,
|
||||
:fillcolor,
|
||||
:foreground_color,
|
||||
:background_color, :foreground_color, :color_palette,
|
||||
:group,
|
||||
:label,
|
||||
:layout,
|
||||
:legend,
|
||||
:colorbar,
|
||||
:linestyle,
|
||||
:linetype,
|
||||
:linewidth,
|
||||
:markershape,
|
||||
:markercolor,
|
||||
:markersize,
|
||||
:markerstrokewidth,
|
||||
:markerstrokecolor,
|
||||
:markerstrokealpha,
|
||||
# :markerstrokestyle,
|
||||
:n,
|
||||
:linecolor, :linestyle, :linewidth, :linealpha,
|
||||
:markershape, :markercolor, :markersize, :markeralpha,
|
||||
:markerstrokewidth, :markerstrokecolor, :markerstrokealpha,
|
||||
:fillrange, :fillcolor, :fillalpha,
|
||||
:nbins,
|
||||
:nc,
|
||||
:nr,
|
||||
# :pos,
|
||||
:n, :nc, :nr, :layout,
|
||||
:smooth,
|
||||
# :ribbon,
|
||||
:show,
|
||||
:size,
|
||||
:title,
|
||||
:windowtitle,
|
||||
:x,
|
||||
:xlabel,
|
||||
:xlims,
|
||||
:xticks,
|
||||
:y,
|
||||
:ylabel,
|
||||
:ylims,
|
||||
:zlims,
|
||||
:yrightlabel,
|
||||
:yticks,
|
||||
:xscale,
|
||||
:yscale,
|
||||
:xflip,
|
||||
:yflip,
|
||||
:title, :windowtitle, :show, :size,
|
||||
:x, :xlabel, :xlims, :xticks, :xscale, :xflip,
|
||||
:y, :ylabel, :ylims, :yticks, :yscale, :yflip,
|
||||
:axis, :yrightlabel,
|
||||
:z, :zlabel, :zlims, :zticks, :zscale, :zflip,
|
||||
:z,
|
||||
:zcolor, # only supported for scatter/scatter3d
|
||||
:tickfont,
|
||||
:guidefont,
|
||||
:legendfont,
|
||||
:grid,
|
||||
# :surface,
|
||||
:levels,
|
||||
:fillalpha,
|
||||
:linealpha,
|
||||
:markeralpha,
|
||||
:overwrite_figure,
|
||||
:xerror,
|
||||
:yerror,
|
||||
:ribbon,
|
||||
:quiver,
|
||||
:tickfont, :guidefont, :legendfont,
|
||||
:grid, :legend, :colorbar,
|
||||
:zcolor, :levels,
|
||||
:xerror, :yerror,
|
||||
:ribbon, :quiver,
|
||||
:orientation,
|
||||
:overwrite_figure,
|
||||
:polar,
|
||||
]
|
||||
supportedAxes(::PyPlotBackend) = _allAxes
|
||||
supportedTypes(::PyPlotBackend) = [:none, :line, :path, :steppre, :steppost, :shape,
|
||||
:scatter, :hist2d, :hexbin, :hist, :density, :bar, :box, :violin, :quiver,
|
||||
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe, :heatmap]
|
||||
supportedTypes(::PyPlotBackend) = [
|
||||
:none, :line, :path, :steppre, :steppost, :shape,
|
||||
:scatter, :hist2d, :hexbin, :hist, :density,
|
||||
:bar, :box, :violin, :quiver,
|
||||
:hline, :vline, :heatmap,
|
||||
:contour, :path3d, :scatter3d, :surface, :wireframe
|
||||
]
|
||||
supportedStyles(::PyPlotBackend) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||
# supportedMarkers(::PyPlotBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
|
||||
supportedMarkers(::PyPlotBackend) = vcat(_allMarkers, Shape)
|
||||
supportedScales(::PyPlotBackend) = [:identity, :ln, :log2, :log10]
|
||||
subplotSupported(::PyPlotBackend) = true
|
||||
|
||||
46
src/plot.jl
46
src/plot.jl
@ -78,62 +78,19 @@ function plot!(plt::Plot, args...; kw...)
|
||||
args = _apply_recipe(d, args...; kw...)
|
||||
|
||||
dumpdict(d, "After plot! preprocessing")
|
||||
# @show groupargs map(typeof, args)
|
||||
|
||||
warnOnUnsupportedArgs(plt.backend, d)
|
||||
|
||||
# just in case the backend needs to set up the plot (make it current or something)
|
||||
_before_add_series(plt)
|
||||
|
||||
# # grouping
|
||||
# groupargs = get(d, :group, nothing) == nothing ? [nothing] : [extractGroupArgs(d[:group], args...)]
|
||||
# # @show groupargs
|
||||
|
||||
# TODO: get the GroupBy object (or nothing), and loop through the groups, doing the following section many times
|
||||
# dumpdict(d, "before", true)
|
||||
groupby = if haskey(d, :group)
|
||||
extractGroupArgs(d[:group], args...)
|
||||
else
|
||||
nothing
|
||||
end
|
||||
# dumpdict(d, "after", true)
|
||||
# @show groupby map(typeof, args)
|
||||
|
||||
_add_series(plt, d, groupby, args...)
|
||||
|
||||
#
|
||||
# # get the list of dictionaries, one per series
|
||||
# @show groupargs map(typeof, args)
|
||||
# dumpdict(d, "before process_inputs")
|
||||
# process_inputs(plt, d, groupargs..., args...)
|
||||
# dumpdict(d, "after process_inputs", true)
|
||||
# seriesArgList, xmeta, ymeta = build_series_args(plt, d)
|
||||
# # seriesArgList, xmeta, ymeta = build_series_args(plt, groupargs..., args...; d...)
|
||||
#
|
||||
# # if we were able to extract guide information from the series inputs, then update the plot
|
||||
# # @show xmeta, ymeta
|
||||
# updateDictWithMeta(d, plt.plotargs, xmeta, true)
|
||||
# updateDictWithMeta(d, plt.plotargs, ymeta, false)
|
||||
#
|
||||
# # now we can plot the series
|
||||
# for (i,di) in enumerate(seriesArgList)
|
||||
# plt.n += 1
|
||||
#
|
||||
# if !stringsSupported()
|
||||
# setTicksFromStringVector(d, di, :x, :xticks)
|
||||
# setTicksFromStringVector(d, di, :y, :yticks)
|
||||
# end
|
||||
#
|
||||
# # remove plot args
|
||||
# for k in keys(_plotDefaults)
|
||||
# delete!(di, k)
|
||||
# end
|
||||
#
|
||||
# dumpdict(di, "Series $i")
|
||||
#
|
||||
# _add_series(plt.backend, plt; di...)
|
||||
# end
|
||||
|
||||
_add_annotations(plt, d)
|
||||
|
||||
warnOnUnsupportedScales(plt.backend, d)
|
||||
@ -150,7 +107,7 @@ function plot!(plt::Plot, args...; kw...)
|
||||
|
||||
current(plt)
|
||||
|
||||
# NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement
|
||||
# note: lets ignore the show param and effectively use the semicolon at the end of the REPL statement
|
||||
# # do we want to show it?
|
||||
if haskey(d, :show) && d[:show]
|
||||
gui()
|
||||
@ -212,6 +169,7 @@ function _add_series(plt::Plot, d::KW, ::Void, args...;
|
||||
if !stringsSupported()
|
||||
setTicksFromStringVector(d, di, :x, :xticks)
|
||||
setTicksFromStringVector(d, di, :y, :yticks)
|
||||
setTicksFromStringVector(d, di, :z, :zticks)
|
||||
end
|
||||
|
||||
# remove plot args
|
||||
|
||||
@ -231,6 +231,8 @@ limsType{T<:Real,S<:Real}(lims::@compat(Tuple{T,S})) = :limits
|
||||
limsType(lims::Symbol) = lims == :auto ? :auto : :invalid
|
||||
limsType(lims) = :invalid
|
||||
|
||||
axis_symbol(letter, postfix) = symbol(letter * postfix)
|
||||
axis_symbols(letter, postfix...) = map(s -> axis_symbol(letter, s), postfix)
|
||||
|
||||
Base.convert{T<:Real}(::Type{Vector{T}}, rng::Range{T}) = T[x for x in rng]
|
||||
Base.convert{T<:Real,S<:Real}(::Type{Vector{T}}, rng::Range{S}) = T[x for x in rng]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user