Hi, I need to insert shapes into a time series using PlotlyJS, and name them. I know how to do it using Plots or PGFPlotsX. For example, what I want is something similar to the following plot, produced with PGFPlotsX after some raw LaTeX code passed into the script:
This material is for teaching, and the combination of Pluto and PlotlyJS looks perfect due to the interactivity that we may get even in static HTML files. I had no problem replicating the example that is available in the PlotlyJS documentation:
Unfortunately, I have failed to accomplish this particular need in PlotlyJS, even in the more archaic version of my demands (just the shapes). Nevertheless, I also need to name the different shapes (as in the first plot above). My example below is not working as intended because I am not correctly passing the type Date array into shapes, and after many twists, I still do not know how to do it.
MWE:
using PlotlyJS
using Dates
using MonthlyDates
My useless efforts surrounded this piece of code:
period10_5 = QuarterlyDate(1960, 1):Quarter(1):QuarterlyDate(2021,1)
y1 = randn(length(period10_5))
y2 = rand(length(period10_5))
#z = period10_5
trace00 = scatter(;x = Date.(period10_5), y = y1,
name = "Shrek", mode="markers+lines",
marker_symbol = "circle", marker_size = "5",
line_width = 0.3 , marker_color = "Blue")
trace01 = scatter(;x = Date.(period10_5), y = y2,
name = "Murphy", mode = "markers+lines",
marker_symbol = "circle", marker_size = "5", line_width = 0.3,
marker_color = "Red")
shapes = rect(["period10_5[50]", "period10_5[70]"], ["period10_5[120]", "period10_5[150]"],
0, 1 ; fillcolor = "red", opacity = 0.2, line_width = 0,
xref = period10_5, yref = "paper")
layout00 = Layout(;title_text = "Shapes, my shapes", title_x = 0.5,
shapes=shapes,
xaxis = attr(
title = "Quarterly obervations",
tickformat = "%Y",
hoverformat = "%Y-Q%q",
tick0 = "1960/01/01",
dtick = "M120"),
#xaxis_range = [1960, 2020],
yaxis_title = "Percentage points",
#yaxis_range=[-2, 2],
titlefont_size = 16)
plot([trace00, trace01], layout00)
This produces the following plot, but I am unable to get the shapes.
Some help will be very much appreciated. Thanks.