如何在绘图2D散点图中添加原始轴下方的箭头

时间:2017-08-08 18:52:12

标签: plot plotly

通过绘图创建2D散点图可以按照以下示例进行:

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

但是,有没有简单的方法在x轴下方添加箭头?

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以在没有文字的情况下使用Plotly annotations

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))