added contourf; getindex for plt/sp; plot/plot! on a Subplot; fix for pyplot zorder

This commit is contained in:
Thomas Breloff 2016-06-29 13:53:22 -04:00
parent 3a4b881576
commit 4ea787743e
9 changed files with 43 additions and 94 deletions

View File

@ -175,6 +175,7 @@ end
@shorthands vline @shorthands vline
@shorthands ohlc @shorthands ohlc
@shorthands contour @shorthands contour
@shorthands contourf
@shorthands contour3d @shorthands contour3d
@shorthands surface @shorthands surface
@shorthands wireframe @shorthands wireframe

View File

@ -79,7 +79,7 @@ add_non_underscore_aliases!(_typeAliases)
like_histogram(seriestype::Symbol) = seriestype in (:histogram, :density) like_histogram(seriestype::Symbol) = seriestype in (:histogram, :density)
like_line(seriestype::Symbol) = seriestype in (:line, :path, :steppre, :steppost) like_line(seriestype::Symbol) = seriestype in (:line, :path, :steppre, :steppost)
like_surface(seriestype::Symbol) = seriestype in (:contour, :contour3d, :heatmap, :surface, :wireframe, :image) like_surface(seriestype::Symbol) = seriestype in (:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image)
is3d(seriestype::Symbol) = seriestype in _3dTypes is3d(seriestype::Symbol) = seriestype in _3dTypes
is3d(series::Series) = is3d(series.d) is3d(series::Series) = is3d(series.d)

View File

@ -423,7 +423,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
if d[:line_z] == nothing if d[:line_z] == nothing
handle = ax[:plot](xyargs...; handle = ax[:plot](xyargs...;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
color = py_linecolor(d), color = py_linecolor(d),
linewidth = py_dpi_scale(plt, d[:linewidth]), linewidth = py_dpi_scale(plt, d[:linewidth]),
linestyle = py_linestyle(st, d[:linestyle]), linestyle = py_linestyle(st, d[:linestyle]),
@ -504,7 +504,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# end # end
# handle = ax[isvertical(d) ? :bar : :barh](x, y; # handle = ax[isvertical(d) ? :bar : :barh](x, y;
# label = d[:label], # label = d[:label],
# zorder = plt.n, # zorder = d[:series_plotindex],
# color = py_fillcolor(d), # color = py_fillcolor(d),
# edgecolor = py_linecolor(d), # edgecolor = py_linecolor(d),
# linewidth = d[:linewidth], # linewidth = d[:linewidth],
@ -518,7 +518,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# extrakw[isvertical(d) ? :width : :height] = 0.0 # extrakw[isvertical(d) ? :width : :height] = 0.0
# handle = ax[isvertical(d) ? :bar : :barh](x, y; # handle = ax[isvertical(d) ? :bar : :barh](x, y;
# label = d[:label], # label = d[:label],
# zorder = plt.n, # zorder = d[:series_plotindex],
# color = py_linecolor(d), # color = py_linecolor(d),
# edgecolor = py_linecolor(d), # edgecolor = py_linecolor(d),
# linewidth = d[:linewidth], # linewidth = d[:linewidth],
@ -552,7 +552,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
handle = ax[:scatter](xyargs...; handle = ax[:scatter](xyargs...;
label = d[:label], label = d[:label],
zorder = plt.n + 0.5, zorder = d[:series_plotindex] + 0.5,
marker = py_marker(d[:markershape]), marker = py_marker(d[:markershape]),
s = py_dpi_scale(plt, d[:markersize] .^ 2), s = py_dpi_scale(plt, d[:markersize] .^ 2),
edgecolors = py_markerstrokecolor(d), edgecolors = py_markerstrokecolor(d),
@ -565,7 +565,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# if st == :histogram # if st == :histogram
# handle = ax[:hist](y; # handle = ax[:hist](y;
# label = d[:label], # label = d[:label],
# zorder = plt.n, # zorder = d[:series_plotindex],
# color = py_fillcolor(d), # color = py_fillcolor(d),
# edgecolor = py_linecolor(d), # edgecolor = py_linecolor(d),
# linewidth = d[:linewidth], # linewidth = d[:linewidth],
@ -594,7 +594,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# end # end
# handle = ax[:hist2d](x, y; # handle = ax[:hist2d](x, y;
# label = d[:label], # label = d[:label],
# zorder = plt.n, # zorder = d[:series_plotindex],
# bins = d[:bins], # bins = d[:bins],
# normed = d[:normalize], # normed = d[:normalize],
# weights = d[:weights], # weights = d[:weights],
@ -619,7 +619,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
handle = ax[:hexbin](x, y; handle = ax[:hexbin](x, y;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
gridsize = d[:bins], gridsize = d[:bins],
linewidths = py_dpi_scale(plt, d[:linewidth]), linewidths = py_dpi_scale(plt, d[:linewidth]),
edgecolors = py_linecolor(d), edgecolors = py_linecolor(d),
@ -660,7 +660,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# contour lines # contour lines
handle = ax[:contour](x, y, z, levelargs...; handle = ax[:contour](x, y, z, levelargs...;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
linewidths = py_dpi_scale(plt, d[:linewidth]), linewidths = py_dpi_scale(plt, d[:linewidth]),
linestyles = py_linestyle(st, d[:linestyle]), linestyles = py_linestyle(st, d[:linestyle]),
cmap = py_linecolormap(d), cmap = py_linecolormap(d),
@ -672,7 +672,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
if d[:fillrange] != nothing if d[:fillrange] != nothing
handle = ax[:contourf](x, y, z, levelargs...; handle = ax[:contourf](x, y, z, levelargs...;
label = d[:label], label = d[:label],
zorder = plt.n + 0.5, zorder = d[:series_plotindex] + 0.5,
cmap = py_fillcolormap(d), cmap = py_fillcolormap(d),
extrakw... extrakw...
) )
@ -705,7 +705,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
handle = ax[st == :surface ? :plot_surface : :plot_wireframe](x, y, z; handle = ax[st == :surface ? :plot_surface : :plot_wireframe](x, y, z;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
rstride = 1, rstride = 1,
cstride = 1, cstride = 1,
linewidth = py_dpi_scale(plt, d[:linewidth]), linewidth = py_dpi_scale(plt, d[:linewidth]),
@ -742,7 +742,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
handle = ax[:plot_trisurf](x, y, z; handle = ax[:plot_trisurf](x, y, z;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
cmap = py_fillcolormap(d), cmap = py_fillcolormap(d),
linewidth = py_dpi_scale(plt, d[:linewidth]), linewidth = py_dpi_scale(plt, d[:linewidth]),
edgecolor = py_linecolor(d), edgecolor = py_linecolor(d),
@ -766,7 +766,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
z # hopefully it's in a data format that will "just work" with imshow z # hopefully it's in a data format that will "just work" with imshow
end end
handle = ax[:imshow](z; handle = ax[:imshow](z;
zorder = plt.n, zorder = d[:series_plotindex],
cmap = py_colormap([:black, :white]), cmap = py_colormap([:black, :white]),
vmin = 0.0, vmin = 0.0,
vmax = 1.0 vmax = 1.0
@ -797,7 +797,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax[:pcolormesh](x, y, z; handle = ax[:pcolormesh](x, y, z;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
cmap = py_fillcolormap(d), cmap = py_fillcolormap(d),
edgecolors = (d[:linewidth] > 0 ? py_linecolor(d) : "face"), edgecolors = (d[:linewidth] > 0 ? py_linecolor(d) : "face"),
extrakw... extrakw...
@ -820,7 +820,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
path = py_path(x, y) path = py_path(x, y)
patches = pypatches.pymember("PathPatch")(path; patches = pypatches.pymember("PathPatch")(path;
label = d[:label], label = d[:label],
zorder = plt.n, zorder = d[:series_plotindex],
edgecolor = py_linecolor(d), edgecolor = py_linecolor(d),
facecolor = py_fillcolor(d), facecolor = py_fillcolor(d),
linewidth = py_dpi_scale(plt, d[:linewidth]), linewidth = py_dpi_scale(plt, d[:linewidth]),
@ -887,7 +887,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
handle = ax[f](args...; handle = ax[f](args...;
zorder = plt.n, zorder = d[:series_plotindex],
facecolor = py_fillcolor(d), facecolor = py_fillcolor(d),
linewidths = 0 linewidths = 0
) )

View File

@ -588,75 +588,15 @@ function prepared_object(plt::Plot)
end end
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# plot to a Subplot
# function get_indices(orig, labels) function plot(sp::Subplot, args...; kw...)
# Int[findnext(labels, l, 1) for l in orig] plt = sp.plt
# end plot(plt, args...; kw..., subplot = findfirst(plt.subplots, sp))
end
# # TODO: remove?? this is the old way of handling discrete data... should be function plot!(sp::Subplot, args...; kw...)
# # replaced by the Axis type and logic plt = sp.plt
# function setTicksFromStringVector(plt::Plot, d::KW, di::KW, letter) plot!(plt, args...; kw..., subplot = findfirst(plt.subplots, sp))
# sym = Symbol(letter) end
# ticksym = Symbol(letter * "ticks")
# pargs = plt.attr
# v = di[sym]
#
# # do we really want to do this?
# typeof(v) <: AbstractArray || return
# isempty(v) && return
# trueOrAllTrue(_ -> typeof(_) <: AbstractString, v) || return
#
# # compute the ticks and labels
# ticks, labels = if ticksType(pargs[ticksym]) == :ticks_and_labels
# # extend the existing ticks and labels. only add to labels if they're new!
# ticks, labels = pargs[ticksym]
# newlabels = filter(_ -> !(_ in labels), unique(v))
# newticks = if isempty(ticks)
# collect(1:length(newlabels))
# else
# maximum(ticks) + collect(1:length(newlabels))
# end
# ticks = vcat(ticks, newticks)
# labels = vcat(labels, newlabels)
# ticks, labels
# else
# # create new ticks and labels
# newlabels = unique(v)
# collect(1:length(newlabels)), newlabels
# end
#
# d[ticksym] = ticks, labels
# plt.attr[ticksym] = ticks, labels
#
# # add an origsym field so that later on we can re-compute the x vector if ticks change
# origsym = Symbol(letter * "orig")
# di[origsym] = v
# di[sym] = get_indices(v, labels)
#
# # loop through existing plt.seriesargs and adjust indices if there is an origsym key
# for sargs in plt.seriesargs
# if haskey(sargs, origsym)
# # TODO: might need to call the setindex function instead to trigger a plot update for some backends??
# sargs[sym] = get_indices(sargs[origsym], labels)
# end
# end
# end
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# function Base.copy(plt::Plot)
# backend(plt.backend)
# plt2 = plot(; plt.attr...)
# for sargs in plt.seriesargs
# sargs = filter((k,v) -> haskey(_series_defaults,k), sargs)
# plot!(plt2; sargs...)
# end
# plt2
# end
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -747,7 +747,14 @@ end
end end
@deps density path @deps density path
# ---------------------------------------------------------------------------
# contourf - filled contours
@recipe function f(::Type{Val{:contourf}}, x, y, z)
fillrange := true
seriestype := :contour
()
end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Error Bars # Error Bars

View File

@ -7,7 +7,7 @@
typealias FuncOrFuncs @compat(Union{Function, AVec{Function}}) typealias FuncOrFuncs @compat(Union{Function, AVec{Function}})
all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none)) all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none))
# missing # missing
convertToAnyVector(v::@compat(Void), d::KW) = Any[nothing], nothing convertToAnyVector(v::@compat(Void), d::KW) = Any[nothing], nothing

View File

@ -39,7 +39,7 @@ function should_add_to_legend(series::Series)
series.d[:primary] && series.d[:label] != "" && series.d[:primary] && series.d[:label] != "" &&
!(series.d[:seriestype] in ( !(series.d[:seriestype] in (
:hexbin,:histogram2d,:hline,:vline, :hexbin,:histogram2d,:hline,:vline,
:contour,:contour3d,:surface,:wireframe, :contour,:contourf,:contour3d,:surface,:wireframe,
:heatmap, :pie, :image :heatmap, :pie, :image
)) ))
end end

View File

@ -83,12 +83,13 @@ function Plot()
Subplot[], false) Subplot[], false)
end end
# TODO: make a decision... should plt[1] return the first subplot or the first series?? # -----------------------------------------------------------------------
# Base.getindex(plt::Plot, i::Integer) = plt.subplots[i]
Base.getindex(plt::Plot, s::Symbol) = plt.spmap[s]
Base.getindex(plt::Plot, r::Integer, c::Integer) = plt.layout[r,c]
attr(plt::Plot, k::Symbol) = plt.attr[k]
attr!(plt::Plot, v, k::Symbol) = (plt.attr[k] = v)
Base.getindex(plt::Plot, i::Integer) = plt.subplots[i]
Base.getindex(plt::Plot, r::Integer, c::Integer) = plt.layout[r,c]
# attr(plt::Plot, k::Symbol) = plt.attr[k]
# attr!(plt::Plot, v, k::Symbol) = (plt.attr[k] = v)
Base.getindex(sp::Subplot, i::Integer) = series_list(sp)[i]
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------

View File

@ -642,7 +642,7 @@ end
# ------------------------------------------------------- # -------------------------------------------------------
# indexing notation # indexing notation
Base.getindex(plt::Plot, i::Integer) = getxy(plt, i) # Base.getindex(plt::Plot, i::Integer) = getxy(plt, i)
Base.setindex!{X,Y}(plt::Plot, xy::Tuple{X,Y}, i::Integer) = setxy!(plt, xy, i) Base.setindex!{X,Y}(plt::Plot, xy::Tuple{X,Y}, i::Integer) = setxy!(plt, xy, i)
Base.setindex!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) = setxyz!(plt, xyz, i) Base.setindex!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) = setxyz!(plt, xyz, i)