问题
There is an example about multiple annotations, it simply duplicate the go.layout.Annotation() to draw 2 arrows.
But I need to draw more than 100+ arrows, I don't know how. The go.layout.Annotation() is tuple type and accepts dict() for each arrow, is there any easy way to add more dict() to tuple() ?
Thank you.
回答1:
I solved my own question.
fig.layout.annotations accepts list, parameters of each arrow is a dict(). So the idea is to create a list of many dict(), and then use fig.update_layout(annotations = list) to draw multiple arrows.
the dict() for each arrow looks like this:
arrow = go.layout.Annotation(dict(
x= x_end,
y= y_end,
xref="x", yref="y",
text="",
showarrow=True,
axref = "x", ayref='y',
ax= x_start,
ay= y_start,
arrowhead = 3,
arrowwidth=1.5,
arrowcolor='rgb(255,51,0)',)
)
the list for multiple arrows can be easily created like this:
list = list + [dict()]
Then, update the fig:
fig.update_layout(
annotations= list_of_all_arrows,)
If all arrows are in time series, this is the final result:
来源:https://stackoverflow.com/questions/58095322/draw-multiple-arrows-using-plotly-python