Put text annotation as background in a scatterplot

I have a plotly line chart with multiple lines and I would like to set a text annotation in the background. I added the text, before the traces, but the text still overlaps the lines (so the background text is supposed to be behind all lines and markers that appear in the chart). I checked the references, but did not find anything that would allow me to set the order in which things appear. Does someone have an idea?

image

You can define the text as a Scatter trace, mode= β€˜text’:


import plotly.graph_objects as go
import numpy as np


y=np.random.randint(1, 8, 5)
a, b = y.min(), y.max()

tr1=go.Scatter(x=np.arange(5),  y=y)
tr0=go.Scatter(x=[2], y=[(a+b)/2], mode='text', text='Background text', textposition='middle center',
               textfont_size=70, textfont_family='Sherif', textfont_color='rgba(50,50,50,0.5)', 
               showlegend=False)

fig=go.Figure(data=[tr0, tr1])

2 Likes