PlotlyJS: subplots with subplot_titles + annotations

@empet, contrary to what I mentioned in my previous post, using your code in a slightly different example works both in VScode and Pluto. In VScode:

using PlotlyJS

p = make_subplots(rows=2, cols=2, specs=[Spec(colspan=2) missing ; Spec() Spec()],
subplot_titles=["First subplot"  "Third subplot" ; "Second subplot" missing],
vertical_spacing = 0.1, horizontal_spacing = 0.09 )

add_trace!(p, scatter(x=1962:2022, y = randn(61), mode = "markers+lines", marker_color="navy", 
            marker_size = 7, marker_symbol = "circle", line_width = 0.5 , linewitdth=0.3, 
            name = "Birds"), 
            row=1, col=1)
	
add_trace!(p, scatter(x=1962:2022, y = randn(61), mode = "markers+lines", marker_color="blue",
            marker_size = 5.5, marker_symbol = "circle", line_width = 0.5 , linewitdth=0.3, 
            name = "Cats"), 
			row=2, col=1)
	
add_trace!(p, scatter(x=1962:2022, y = randn(61), mode = "markers+lines", marker_color="maroon",
            marker_size = 5.5, marker_symbol = "circle", line_width = 0.5 , linewitdth = 0.3, 
			name = "Dogs" ), 
			row=2, col=2)

	annotations=[
		attr(x=1999 , y=2.5, text="One cat", showarrow=false, arrowhead=1 ),
        attr(x=2008 , y=2.5, text="One dog", showarrow=false, arrowhead=1 ),
        attr(x=2019 , y=2.5, text="One frog", showarrow=false, yshift=0 )]

	
relayout!(p, showlegend=true, title_text = "Figure with subplots and annotations", 
            height = "700", xaxis_range = [1960, 2023], hovermode = "x", yaxis_range=[-3 , 3])	
	
append!(p.plot.layout.annotations, annotations)

add_shape!(p, line( x0=2001, y0=-3, x1=2001, y1=3,  line=attr(color="RoyalBlue", width=1.5, 
            dash="dashdot")), row=1, col=1)
	
add_shape!(p, line( x0=2008, y0=-3, x1=2008, y1=3,  line=attr(color="RoyalBlue", width=1.5, 
            dash="dashdot")), row=1, col=1)
	
add_shape!(p, line( x0=2019, y0=-3, x1=2019, y1=3,  line=attr(color="RoyalBlue", width=1.5, 
            dash="dashdot")), row=1, col=1)
p

with the plot:

1 Like