Harxish
Harxish

Reputation: 459

Annotations in facet plots plotly

I'm creating a facet plot with plotly, which has two columns and a single row. I also have a list of dict for annotations, which looks like this...

annots = [{'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 398000), 'y': 125.5, 'text': '8', 'font': {'color': 'black'}},
          {'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 545000), 'y': 123.5, 'text': '3', 'font': {'color': 'black'}},
          {'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 583000), 'y': 120.5, 'text': '9', 'font': {'color': 'black'}}]

I create layout dictionary and pass it to the figure object like this...

layout = dict(showlegend=False, height=HEIGHT, annotations=annots, barmode='overlay', hoverlabel=hoverlabel, legend=legend, margin=margin, xaxis=xaxes1, xaxis2=xaxes2, yaxis=yaxes1, yaxis2=yaxes2)
fig = go.Figure(data=data, layout=layout)

But all the annotations are displayed in the first column. How do I specify which annotations belong to which facet plot ?

Upvotes: 1

Views: 2079

Answers (1)

Harxish
Harxish

Reputation: 459

It was very easy, I just need to specify xref and yref as keys in the dictionary. So it looks like this...

annots = [{'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 398000), 'y': 125.5, 'text': '8', 'xref'='x2', 'font': {'color': 'black'}},
          {'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 545000), 'y': 123.5, 'text': '3', 'xref'='x2', 'font': {'color': 'black'}},
          {'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 583000), 'y': 120.5, 'text': '9', 'xref'='x', 'font': {'color': 'black'}}]

Upvotes: 3

Related Questions