From 5d935d29c5cb23b65884b214daa58842cc86f4af Mon Sep 17 00:00:00 2001 From: Andy Nowacki Date: Wed, 7 Jul 2021 13:18:52 +0100 Subject: [PATCH 1/2] Document use of tuples in annotations attribute The `annotations` attribute (and `annotate!` function) has supported the use of plain tuples containing arguments which are passed to `text` since v0.22.2. Document this option in the list of SubPlot attributes and in example 20. Closes (mostly) https://github.com/JuliaPlots/RecipesBase.jl/issues/72 but note that `series_annotations` does not yet support passing tuples of arguments for `Plots.text`. --- src/arg_desc.jl | 2 +- src/examples.jl | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 9ea4f463e..d490d8c9b 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -115,7 +115,7 @@ const _arg_desc = KW( :colorbar_formatter => "Function, :scientific, :plain or :auto. A method which converts a number to a string for tick labeling.", :legendfont => "Font. Font of legend items.", :legendtitlefont => "Font. Font of the legend title.", -:annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String or PlotText (created with `text(args...)`) Add one-off text annotations at the x,y coordinates.", +:annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String, PlotText (created with `text(args...)`), or a tuple of arguments to `text` (e.g., `(\"Label\", 8, :red, :top)`). Add one-off text annotations at the x,y coordinates.", :annotationfontfamily => "String or Symbol. Font family of annotations.", :annotationfontsize => "Integer. Font pointsize of annotations.", :annotationhalign => "Symbol. horizontal alignment of annotations, :hcenter, :left, :right or :center.", diff --git a/src/examples.jl b/src/examples.jl index 191080bb2..46742fbd4 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -370,10 +370,19 @@ const _examples = PlotExample[ "Annotations", """ The `annotations` keyword is used for text annotations in data-coordinates. Pass in a - tuple (x,y,text) or a vector of annotations. `annotate!(ann)` is shorthand for `plot!(; - annotation=ann)`. Series annotations are used for annotating individual data points. - They require only the annotation... x/y values are computed. A `PlotText` object can be - build with the method `text(string, attr...)`, which wraps font and color attributes. + tuple `(x, y, text)`, or a vector of annotations, each of which is a tuple of `x`, `y` + and `text`. + `text` may be a simple `String`, or a `PlotText` object, which can be + built with the method `text(string, attrs...)`. + This wraps font and color attributes and allows you to set text styling. + `text` may also be a tuple `(string, attrs...)` of arguments which are passed + to `Plots.text`. + + `annotate!(ann)` is shorthand for `plot!(; annotation=ann)`. + + Series annotations are used for annotating individual data points. + They require only the annotation; x/y values are computed. Series annotations + require either plain `String`s or `PlotText` objects. """, [ :( @@ -385,11 +394,11 @@ const _examples = PlotExample[ leg = false, ) annotate!([ - (5, y[5], Plots.text("this is #5", 16, :red, :center)), + (5, y[5], ("this is #5", 16, :red, :center)), ( 10, y[10], - Plots.text("this is #10", :right, 20, "courier"), + ("this is #10", :right, 20, "courier"), ), ]) scatter!( From 0e25767cd34856a9a6b26131273363ddd6d5cd3d Mon Sep 17 00:00:00 2001 From: Andy Nowacki Date: Thu, 8 Jul 2021 11:22:44 +0100 Subject: [PATCH 2/2] Document use of tuples in annotate! shorthand Include a description of the use of vectors of plain tuples in the docstring for `annotate!`. --- src/shorthands.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shorthands.jl b/src/shorthands.jl index dfcc23023..74a7b26c0 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -453,12 +453,14 @@ Add annotations to an existing plot. # Arguments - `anns`: An `AbstractVector` of tuples of the form `(x,y,text)`. The `text` object - can be a `String` or `PlotText`. + can be a `String`, `PlotText` PlotText (created with `text(args...)`), + or a tuple of arguments to `text` (e.g., `("Label", 8, :red, :top)`). # Example ```julia-repl julia> plot(1:10) julia> annotate!([(7,3,"(7,3)"),(3,7,text("hey", 14, :left, :top, :green))]) +julia> annotate!([(4, 4, ("More text", 8, 45.0, :bottom, :red))]) ``` """ annotate!(anns...; kw...) = plot!(; annotation = anns, kw...)