Home > Blockchain >  Arrows in plotly python
Arrows in plotly python

Time:09-09

I would like to add arrows to plotly figure. I looked at this question enter image description here

Thank you so much

CodePudding user response:

The response you are referring to may be difficult to understand because it is a partial code. You can efficiently add multiple arrows by adding a single arrow setting to the list. x,y is the end point of the arrow and ax,ay is the start point of the arrow. I have modified some of the data presented and added the data to draw the arrows along with the points on the scatterplot.

fig = px.scatter(df, x='a', y='b', error_y='c')

fig.update_xaxes(title_font_family="Trebuchet")
fig.update_layout(yaxis=dict(scaleanchor="x", scaleratio=1),
                  template = "plotly_white",
                  title="<b>V</b>",
                 )
fig.update_layout(xaxis = dict(autorange="reversed"))

x_end = [1, 2, 2]
y_end = [3, 5, 4]
x_start = [0, 1, 3]
y_start = [4, 4, 4]

list_of_all_arrows = []
for x0,y0,x1,y1 in zip(x_end, y_end, x_start, y_start):
    arrow = go.layout.Annotation(dict(
                    x=x0,
                    y=y0,
                    xref="x", yref="y",
                    text="",
                    showarrow=True,
                    axref="x", ayref='y',
                    ax=x1,
                    ay=y1,
                    arrowhead=3,
                    arrowwidth=1.5,
                    arrowcolor='rgb(255,51,0)',)
                )
    list_of_all_arrows.append(arrow)

fig.update_layout(annotations=list_of_all_arrows)
# fig.write_html("Fig.html")
fig.show()

enter image description here

  • Related