working on annotations

This commit is contained in:
Thomas Breloff 2015-09-28 11:09:45 -04:00
parent fd3a4d0a0e
commit eafc1a784c
6 changed files with 66 additions and 119 deletions

View File

@ -168,6 +168,7 @@ xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
annotate!(annotations) = plot!(annotation = annotations)
```
Some keyword arguments you can set:

File diff suppressed because one or more lines are too long

View File

@ -43,6 +43,7 @@ export
ylims!,
xticks!,
yticks!,
annotate!,
savepng,
gui,
@ -96,21 +97,23 @@ ohlc(args...; kw...) = plot(args...; kw..., linetype = :ohlc)
ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc)
title!(s::AbstractString) = plot!(title = s)
xlabel!(s::AbstractString) = plot!(xlabel = s)
ylabel!(s::AbstractString) = plot!(ylabel = s)
title!(s::AbstractString) = plot!(title = s)
xlabel!(s::AbstractString) = plot!(xlabel = s)
ylabel!(s::AbstractString) = plot!(ylabel = s)
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
annotate!(anns) = plot!(annotation = anns)
title!(plt::Plot, s::AbstractString) = plot!(plt; title = s)
xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s)
ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s)
xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; xlims = lims)
ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; ylims = lims)
xticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; xticks = v)
yticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; yticks = v)
title!(plt::Plot, s::AbstractString) = plot!(plt; title = s)
xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s)
ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s)
xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; xlims = lims)
ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; ylims = lims)
xticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; xticks = v)
yticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; yticks = v)
annotate!(plt::Plot, anns) = plot!(plt; annotation = anns)
# ---------------------------------------------------------

View File

@ -390,96 +390,3 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
end
# # note: idx is the index of this series within this call, n is the index of the series from all calls to plot/subplot
# function getPlotKeywordArgs(pkg::PlottingPackage, kw, idx::Int, n::Int)
# d = Dict(kw)
# # # replace alternate names
# # for tup in kw
# # if haskey(ALT_ARG_NAMES, tup)
# # d[tup[1]] = ALT_ARG_NAMES[tup]
# # end
# # end
# # default to a white background, but only on the initial call (so we don't change the background automatically)
# if haskey(d, :background_color)
# d[:background_color] = getRGBColor(d[:background_color])
# elseif n == 0
# d[:background_color] = colorant"white"
# end
# # fill in d with either 1) plural value, 2) value, 3) default
# for k in keys(PLOT_DEFAULTS)
# plural = makeplural(k)
# if !haskey(d, k)
# if n == 0 || k != :size
# d[k] = haskey(d, plural) ? autopick(d[plural], idx) : PLOT_DEFAULTS[k]
# end
# end
# delete!(d, plural)
# end
# # auto-pick
# if n > 0
# if d[:axis] == :auto
# d[:axis] = autopick_ignore_none_auto(supportedAxes(pkg), n)
# end
# # if d[:linetype] == :auto
# # d[:linetype] = autopick_ignore_none_auto(supportedTypes(pkg), n)
# # end
# if d[:linestyle] == :auto
# d[:linestyle] = autopick_ignore_none_auto(supportedStyles(pkg), n)
# end
# if d[:marker] == :auto
# d[:marker] = autopick_ignore_none_auto(supportedMarkers(pkg), n)
# end
# end
# # # swap out dots for no line and a marker
# # if haskey(d, :linetype) && d[:linetype] == :scatter
# # d[:linetype] = :none
# # if d[:marker] == :none
# # d[:marker] = :ellipse
# # end
# # end
# # handle plot initialization differently
# if n == 0
# delete!(d, :x)
# delete!(d, :y)
# else
# # once the plot is created, we can get line/marker colors
# # update color
# d[:color] = getRGBColor(d[:color], n)
# # update markercolor
# mc = d[:markercolor]
# mc = (mc == :match ? d[:color] : getRGBColor(mc, n))
# d[:markercolor] = mc
# # set label
# label = d[:label]
# label = (label == "AUTO" ? "y$n" : label)
# if d[:axis] == :right && length(label) >= 4 && label[end-3:end] != " (R)"
# label = string(label, " (R)")
# end
# d[:label] = label
# warnOnUnsupported(pkg, d)
# end
# d
# end
# -----------------------------------------------------------------------------
# TODO: arg aliases

View File

@ -310,17 +310,9 @@ function createAnnotationObject(x, y, val::AbstractString)
))
end
function addAnnotations(plt::Plot{GadflyPackage}, d::Dict)
if haskey(d, :annotation)
anns = d[:annotation]
if !(isa(anns, AbstractVector) && issubtype(eltype(anns), Tuple))
error("Expecting a vector of tuples for annotations: (x, y, annotation)\n got: $(typeof(anns))")
end
for ann in anns
x, y, val = ann
push!(plt.o.guides, createAnnotationObject(x, y, val))
end
function addAnnotations{X,Y,V}(plt::Plot{GadflyPackage}, anns::AVec{Tuple{X,Y,V}})
for ann in anns
push!(plt.o.guides, createAnnotationObject(ann...))
end
end

View File

@ -129,6 +129,8 @@ function plot!(plt::Plot, args...; kw...)
plt
end
# --------------------------------------------------------------------
function setTicksFromStringVector(d::Dict, di::Dict, sym::Symbol, ticksym::Symbol)
# if the x or y values are strings, set ticks to the unique values, and x/y to the indices of the ticks
# @show get(d,ticksym,:auto) == :auto isa(di[sym], AbstractArray) isa(eltype(di[sym]), AbstractString)
@ -142,8 +144,11 @@ function setTicksFromStringVector(d::Dict, di::Dict, sym::Symbol, ticksym::Symbo
# @show sym ticksym di[sym] d[ticksym]
end
# --------------------------------------------------------------------
preparePlotUpdate(plt::Plot) = nothing
# --------------------------------------------------------------------
# should we update the x/y label given the meta info during input slicing?
function updateDictWithMeta(d::Dict, initargs::Dict, meta::Symbol, isx::Bool)
@ -154,6 +159,21 @@ function updateDictWithMeta(d::Dict, initargs::Dict, meta::Symbol, isx::Bool)
end
updateDictWithMeta(d::Dict, initargs::Dict, meta, isx::Bool) = nothing
# --------------------------------------------------------------------
annotations(::Void) = []
annotations{X<:Real, Y<:Real, V}(v::AVec{Tuple{X,Y,V}}) = v
annotations{X<:Real, Y<:Real, V}(t::Tuple{X,Y,V}) = [t]
annotations(anns) = error("Expecting a tuple (or vector of tuples) for annotations: ",
"(x, y, annotation)\n got: $(typeof(anns))")
function addAnnotations(plt::Plot, d::Dict)
anns = annotations(get(d, :annotation, nothing))
if !isempty(anns)
addAnnotations(plt, anns)
end
end
# --------------------------------------------------------------------