Reputation: 183
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
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)
Upvotes: 4