JuliaPlots / PlotlyJS.jl

Julia library for plotting with plotly.js
Other
422 stars 78 forks source link

annotation #290

Closed IgorDouven closed 5 years ago

IgorDouven commented 5 years ago

Hi all,

This is probably a beginner's question, but I can't figure out how to do the following: I'd like to have a particular annotation (say, a letter, a word, a symbol) at a specific place in the plot. From the plotly document I had understood that something like this should work: annotate!(p, (x_coord, y_coord, "foo")), where p is a previously created plot. But it doesn't. What am I doing wrong or overlooking? Relatedly, if I want a symbol, can I use LaTeX input? Thanks in advance.

sglyon commented 5 years ago

Hi @IgorDouven happy to help here. Could you post a snippet from the plotly docs that show how to create an annotation? It could be from javascript, R, or python plotly libraries.

Thanks!

IgorDouven commented 5 years ago

Hi Spencer, thanks for your reply. I think what I saw was the PlotlyJS page on Julia plots: https://docs.juliaplots.org/latest/examples/plotlyjs/. I know this is for the PlotlyJS backend for Plots, but I was assuming the same syntax would work for PlotlyJS. Again, however, I'm completely new to this, having switched from Gadfly (or calling R and ggplot).

Op ma 19 aug. 2019 om 18:14 schreef Spencer Lyon notifications@github.com:

Hi @IgorDouven https://github.com/IgorDouven happy to help here. Could you post a snippet from the plotly docs that show how to create an annotation? It could be from javascript, R, or python plotly libraries.

Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sglyon/PlotlyJS.jl/issues/290?email_source=notifications&email_token=AIFACLFUO2AXRGJSJP4Z5XLQFLBGVA5CNFSM4INCKMCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4TPQBQ#issuecomment-522647558, or mute the thread https://github.com/notifications/unsubscribe-auth/AIFACLFO7AJPOR7JSU6TH23QFLBGVANCNFSM4INCKMCA .

sglyon commented 5 years ago

Ahh I see, nope that won't quite work here.

here's an example of how to do this in PlotlyJS:

julia> using PlotlyJS

julia> x = 0:0.1:10;

julia> y = sin.(x);

julia> layout = Layout(annotations=[attr(x=π/2, y=sin(π/2), text="This is pi/2!")])
layout with fields annotations and margin

julia> plot(scatter(x=x, y=y), layout)

Which results in

annotation

The API is that you pass an array of annotation objects to the annotations field of the layout.

You can add any of these attributes to the annotation object: https://plot.ly/javascript/reference/#layout-annotations

IgorDouven commented 5 years ago

Many thanks Spencer, that's very helpful!

Op ma 19 aug. 2019 om 21:20 schreef Spencer Lyon notifications@github.com:

Ahh I see, nope that won't quite work here.

here's an example of how to do this in PlotlyJS:

julia> using PlotlyJS

julia> x = 0:0.1:10;

julia> y = sin.(x);

julia> layout = Layout(annotations=[attr(x=π/2, y=sin(π/2), text="This is pi/2!")])

layout with fields annotations and margin

julia> plot(scatter(x=x, y=y), layout)

Which results in

[image: annotation] https://user-images.githubusercontent.com/1001948/63292910-c5251180-c294-11e9-8f8d-c9488b474510.png

The API is that you pass an array of annotation objects to the annotations field of the layout.

You can add any of these attributes to the annotation object: https://plot.ly/javascript/reference/#layout-annotations

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sglyon/PlotlyJS.jl/issues/290?email_source=notifications&email_token=AIFACLE3KMROC3ODMV4OH43QFLXAHA5CNFSM4INCKMCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4UAVKY#issuecomment-522717867, or mute the thread https://github.com/notifications/unsubscribe-auth/AIFACLAZLMRHX6CXUBIPNS3QFLXAHANCNFSM4INCKMCA .