The problem in my previous entry was not reproducible. It was entirely dependent on my data.
Below I present an MWE that can be easily reproducible.
1 - Defining shapes (two rectangles):
shapes1 = rect([5, 25], [10, 30],
0, 1; fillcolor = "red", opacity = 0.1, line_width = 0,
xref="x", yref = "paper");
2 - Producing the two individual plots:
function noise1()
trace1 = scatter(;x=1:40, y=randn(40), name = "some")
layout1 = Layout(;
shapes = shapes1,
title_text = "Some noise",
title_x = 0.5,
hovermode = "x",
titlefont_size = 16)
fig1 = plot(trace1, layout1)
end
noise1()
function noise2()
trace2 = scatter(;x=1:40, y=rand(40), name = "more")
layout2 = Layout(;
shapes = shapes1,
title_text = "More noise",
title_x = 0.5,
hovermode = "x",
titlefont_size = 16)
fig2 = plot(trace2, layout2)
end
noise2()
3 - Creating the subplots
fig3= [noise1() noise2()]
relayout!(fig3, Layout(; hovermode="x", shapes = shapes1))
fig3
The strange problem: why do shapes
only appear in the first subplot? How can I force them to be in the second plot as well?
Thanks