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[:reg] = false # regression line?
|
||||||
_seriesDefaults[:group] = nothing
|
_seriesDefaults[:group] = nothing
|
||||||
_seriesDefaults[:ribbon] = nothing
|
_seriesDefaults[:ribbon] = nothing
|
||||||
|
_seriesDefaults[:annotation] = nothing
|
||||||
_seriesDefaults[:args] = [] # additional args to pass to the backend
|
_seriesDefaults[:args] = [] # additional args to pass to the backend
|
||||||
_seriesDefaults[:kwargs] = [] # additional keyword args to pass to the backend
|
_seriesDefaults[:kwargs] = [] # additional keyword args to pass to the backend
|
||||||
# note: can be Vector{Dict} or Vector{Tuple}
|
# note: can be Vector{Dict} or Vector{Tuple}
|
||||||
@ -186,6 +187,10 @@ const _keyAliases = Dict(
|
|||||||
:area => :fillto,
|
:area => :fillto,
|
||||||
:g => :group,
|
:g => :group,
|
||||||
:r => :ribbon,
|
:r => :ribbon,
|
||||||
|
:ann => :annotation,
|
||||||
|
:anns => :annotation,
|
||||||
|
:annotate => :annotation,
|
||||||
|
:annotations => :annotation,
|
||||||
:xlab => :xlabel,
|
:xlab => :xlabel,
|
||||||
:ylab => :ylabel,
|
:ylab => :ylabel,
|
||||||
:yrlab => :yrightlabel,
|
: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)
|
# create the underlying object (each backend will do this differently)
|
||||||
function buildSubplotObject!(subplt::Subplot{GadflyPackage})
|
function buildSubplotObject!(subplt::Subplot{GadflyPackage})
|
||||||
subplt.o = nothing
|
subplt.o = nothing
|
||||||
|
|||||||
@ -114,6 +114,8 @@ function plot!(plt::Plot, args...; kw...)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
addAnnotations(plt, d)
|
||||||
|
|
||||||
# add title, axis labels, ticks, etc
|
# add title, axis labels, ticks, etc
|
||||||
updatePlotItems(plt, d)
|
updatePlotItems(plt, d)
|
||||||
currentPlot!(plt)
|
currentPlot!(plt)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user