Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw multiple arrows using plotly python

Tags:

plotly

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.

like image 422
ERIC Avatar asked Oct 22 '25 19:10

ERIC


1 Answers

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: enter image description here

like image 80
ERIC Avatar answered Oct 27 '25 07:10

ERIC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!