Plots annotate

With recent version of Plots (1.0.11) and GR backend:

annotate!(x,y,t)

doesn’t work anymore, I must use:

annotate!((x,y,t))

If you find a bug you should open a github issue on the relevant repository

2 Likes

“The relevant repository”, that is the question ! I never posted github issues, I am afraid we will waste more time if I try it personally, I apologize.

This (collaboration, giving and taking) is the base of open source, from which you seem to benefit.
I understand that not everybody wants to or is able to give something back, but I can assure you, opening a github issue (relevant repository can be at a first step: https://github.com/JuliaPlots/Plots.jl) can be done fast and easily. Doing it assures, that the bug you found is not lost until someone else is stumbling over it (and opens an issue), which I am sure will take much more time.
Just think if Julia has saved you time already (or even gave you a good time) and if this is the case you may rethink your position. Thank you.

5 Likes

Quote from the docs http://docs.juliaplots.org/latest/generated/gr/#gr-ref20-1 :

The annotations keyword is used for text annotations in data-coordinates. Pass in a
tuple (x,y,text) or a vector of annotations.

So for me, this is not a bug, but a bug fix, but I can’t find out if the docs have changed.

1 Like

You’re right, but the simple form annotate!(x,y,text) worked until recently (and arguments of any function are, by definition, a tuple). Here is a part of the error message that I get now, with explicit reference to a shorthand notation:

MethodError: no method matching process_annotation(::Plots.Subplot{Plots.GRBackend}, ::Float64)
[...]
#annotate!#421 at shorthands.jl:441 [inlined]
annotate!(::Float64, ::Float64, ::String) at shorthands.jl:441

annotate!(x,y,text) works with Plots@1.0.2, but no more with Plots@1.0.4. Github documentation of versions 1.0.3 and 1.0.4 says that annotations were fixed, but I don’t understand the corresponding issues.

Checking the code in shorthands.jl

show whats happening.

Before:

annotate!(anns...; kw...) = plot!(; annotation = anns, kw...)

After:

annotate!(anns...; kw...) = plot!(; annotation = collect(anns), kw...)

Now the problem is, that collect returns an Array{AbstractArray{T,1} where T,1} and this is not accepted by plot!( ...; annotation(s?) = ...)
(I believe it’s a bit more complicated, but I didn’t dig deeper)

A possible fix would be:

annotate!(anns...; kw...) = plot!(; annotations = (collect.(anns)), kw...)

(I don’t know why it is annotation and not annotations as it should be, just as a side node).

So, this analysis took a bit (of my and your) time. How about opening an issue at Issues · JuliaPlots/Plots.jl · GitHub ?

It’s now just your initial use case with a link to this discussion and maybe creating an account at github.

I am afraid we will waste more time if I try it personally

I am sure this time is not wasted!

2 Likes

This issue is also related to this:
https://github.com/JuliaPlots/Plots.jl/issues/2487

Opened an issue:
https://github.com/JuliaPlots/Plots.jl/issues/2601

Oh sorry, you persuaded me to open an issue (#2595), but I didn’t signal it here, and #2595 was quickly closed by a developer and replaced by pull request #2597.

3 Likes

Well done! :laughing:

2 Likes