Hi All,
I am trying to add annotations to sub plots in a figure but there doesn’t seem to be a way of specifying which sub-plot the annotation appears in. It always appears in the first sub-plot.
How can I specify the sub plot in which to place the annotation?
Here is an example in Julia and the result:
##########
using Plots
using PlotlyJS
const pjs = PlotlyJS; # Create and alias for PlotlyJS
# generate some test data
theta = -pi:pi/100:pi
# create the traces
tan_plt = pjs.scatter(x=θ, y=tan.(θ), name="tan(θ)");
sin_plt = pjs.scatter(x=θ, y=sin.(θ), name="sin(θ)");
cos_plt = pjs.scatter(x=θ, y=cos.(θ), name="cos(θ)");
# create a figure with 3 sub_plots to hold the traces
trigfig = make_subplots(rows=3, cols=1, shared_xaxes=true,
row_heights=[0.25, 0.25,0.5], vertical_spacing=0.01);
# add the traces to the figure, one in each sub-plot
add_trace!(trigfig, tan_plt, row=1, col=1);
add_trace!(trigfig, sin_plt, row=2, col=1);
add_trace!(trigfig, cos_plt, row=3, col=1);
# create some annotations
annots = [
attr(x=pi/2, y=0,
text="π/2",
showarrow=true, arrowcolor="limegreen",
arrowhead=1, arrowwidth=3,
font=attr(
family="Courier New, monospace",
size=16,
color="limegreen"
)
),
];
# Update the figure and add annotations
relayout!(trigfig, width=640, height=480, title="Basic trig functions",
yaxis_title="tan(θ)", yaxis2_title="sin(θ)", yaxis3_title="cos(θ)",
yaxis_type=:log,
plot_bgcolor=:lightgray, paper_bgcolor=:lightgray,
annotations=annots
);
#display the plot
trigfig