david78
david78

Reputation: 183

In Python Plotly, annotation is always on the top-left of a target point. How to annotate under a target point?

In Python, Plotly annotates always on the top-left of a target point (see the below line). However, I would like to annotate on the bottom-center of a point.

Please help with this. Thank you in advance for any comment.

import plotly.graph_objs as go
import plotly.io as pio
pio.renderers.default = 'browser'

x = list(range(1, 10))
y = list(range(21, 30))

fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y))

fig.add_annotation(x=x[4], y=y[4], arrowsize=2, text='Alway on the top-left')

pio.show(fig)

Upvotes: 2

Views: 2776

Answers (1)

Derek O
Derek O

Reputation: 19565

You can use the parameters ax and ay to control the direction of the arrow (and the text will be positioned accordingly).

For example:

import plotly.graph_objs as go
import plotly.io as pio
pio.renderers.default = 'browser'

x = list(range(1, 10))
y = list(range(21, 30))

fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y))

fig.add_annotation(x=x[4], y=y[4], arrowsize=2, text='text underneath', ax=10, ay=30)

pio.show(fig)

enter image description here

Upvotes: 4

Related Questions