working on annotations
This commit is contained in:
parent
77d679b63b
commit
fd3a4d0a0e
67
examples/annotate.ipynb
Normal file
67
examples/annotate.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -105,6 +105,7 @@ _seriesDefaults[:fillto] = nothing # fills in the area
|
||||
_seriesDefaults[:reg] = false # regression line?
|
||||
_seriesDefaults[:group] = nothing
|
||||
_seriesDefaults[:ribbon] = nothing
|
||||
_seriesDefaults[:annotation] = nothing
|
||||
_seriesDefaults[:args] = [] # additional args to pass to the backend
|
||||
_seriesDefaults[:kwargs] = [] # additional keyword args to pass to the backend
|
||||
# note: can be Vector{Dict} or Vector{Tuple}
|
||||
@ -186,6 +187,10 @@ const _keyAliases = Dict(
|
||||
:area => :fillto,
|
||||
:g => :group,
|
||||
:r => :ribbon,
|
||||
:ann => :annotation,
|
||||
:anns => :annotation,
|
||||
:annotate => :annotation,
|
||||
:annotations => :annotation,
|
||||
:xlab => :xlabel,
|
||||
:ylab => :ylabel,
|
||||
:yrlab => :yrightlabel,
|
||||
|
||||
@ -301,6 +301,32 @@ end
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
|
||||
function createAnnotationObject(x, y, val::AbstractString)
|
||||
Gadfly.Guide.annotation(Compose.compose(
|
||||
Compose.context(),
|
||||
Compose.text(x, y, val)
|
||||
# Compose.fill(colorant"black"),
|
||||
# Compose.stroke(colorant"black")
|
||||
))
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
|
||||
# create the underlying object (each backend will do this differently)
|
||||
function buildSubplotObject!(subplt::Subplot{GadflyPackage})
|
||||
subplt.o = nothing
|
||||
|
||||
@ -114,6 +114,8 @@ function plot!(plt::Plot, args...; kw...)
|
||||
|
||||
end
|
||||
|
||||
addAnnotations(plt, d)
|
||||
|
||||
# add title, axis labels, ticks, etc
|
||||
updatePlotItems(plt, d)
|
||||
currentPlot!(plt)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user