PlotlyJS: how to introduce shapes into time series?

Hi @empet, thank you very much for your quick reply. I could never get close to your solution, no way. It works very well.

In the meantime, I was desperately trying to come up with a way of solving the problem. I found a workaround that works as well, certainly a bit clumsy. It takes one more step than in your code. I have to covert an array of Date types (named as “Quarters”) in “my_df” into an array of strings:

my_strings = my_df[!,:Quarters] = string.(my_df[:,:Quarters])

Then I applied the same logic in the docs’s example, using the strings to define the rectangles I want.

my_strings = my_df[!,:Quarters] = string.(my_df[:,:Quarters]) # Date type into strings
period10_5 = QuarterlyDate(1960, 1):Quarter(1):QuarterlyDate(2021,1)
y1 = randn(length(period10_5))
y2 = rand(length(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(["1962-07-01", "2010-07-01"], ["1970-01-01", "2018-01-01"],
               0, 1; fillcolor = "gray", opacity = 0.2, line_width = 0,
               xref = my_strings, yref = "paper")
	
layout00 = Layout(; title_text = "Shapes, my shapes", title_x = 0.5,

		       shapes = shapes,
		
		       annotations = [attr(x = "1966-07-01", y = 2.5, showarrow = false,
				                     text = "QE1"), 
			                  attr(x = "2014-03-01", y = 2.5, showarrow = false, 
				                     text = "QE2") ],
		
            	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)

The plot looks like this:

Thanks a lot.