Draw multiple arrows using plotly python

ぐ巨炮叔叔 提交于 2021-01-01 08:14:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!