0
votes

Creating 2D scatter plot by plotly can be done following the example from:

https://plot.ly/python/line-and-scatter/

However, is there any easy way to add arrows below the x axis?

enter image description here

1

1 Answers

2
votes

You could use Plotly's annotations without text.

enter image description here

import plotly
import numpy as np

plotly.offline.init_notebook_mode()
N = 1000

data = [plotly.graph_objs.Scatter(x=np.random.randn(N),
                                  y=np.random.randn(N),
                                  mode = 'markers'
                                 )
       ]

xstart = -2
xmax = 3.5
xmin = -3.5
padding = 0.05
ypos = -0.1

layout = plotly.graph_objs.Layout(
    xaxis=dict(range=[xmin, xmax]),
    showlegend=False,
    annotations=[
        dict(
            x=xmin,
            y=ypos,
            ax=xstart + padding,
            ay=ypos,
            xref='x',
            axref='x',
            yref='paper',
            ayref='paper',
            showarrow=True,
            arrowhead=2,
            arrowsize=1,
            arrowwidth=3,
            arrowcolor='#0000ff',
        ),
        dict(
            x=xmax,
            y=ypos,
            ax=xstart - padding,
            ay=ypos,
            xref='x',
            axref='x',
            yref='paper',
            ayref='paper',
            showarrow=True,
            arrowhead=2,
            arrowsize=1,
            arrowwidth=3,
            arrowcolor='#ff0000',
        )
    ])

plotly.offline.iplot(plotly.graph_objs.Figure(data=data, 
                                              layout=layout))