如何在二维散点图中的原始轴下方添加箭头 [英] How to add arrows below the original axis in plotly 2D scatter plot

查看:50
本文介绍了如何在二维散点图中的原始轴下方添加箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

你可以使用 Plotly 的

plotly 导入将 numpy 导入为 npplotly.offline.init_notebook_mode()N = 1000数据 = [plotly.graph_objs.Scatter(x=np.random.randn(N),y=np.random.randn(N),模式 = '标记')]xstart = -2xmax = 3.5xmin = -3.5填充 = 0.05ypos = -0.1布局 = plotly.graph_objs.Layout(xaxis=dict(range=[xmin, xmax]),showlegend=假,注释=[字典(x=xmin,y=ypos,ax=xstart + 填充,ay=ypos,外部参照='x',axref='x',yref='纸',ayref='纸',显示箭头=真,箭头=2,箭头大小=1,箭头宽度=3,箭头颜色='#0000ff',),字典(x=xmax,y=ypos,ax=xstart - 填充,ay=ypos,外部参照='x',axref='x',yref='纸',ayref='纸',显示箭头=真,箭头=2,箭头大小=1,箭头宽度=3,箭头颜色='#ff0000',)])plotly.offline.iplot(plotly.graph_objs.Figure(data=data,布局=布局))

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?

解决方案

You could use Plotly's annotations without text.

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

这篇关于如何在二维散点图中的原始轴下方添加箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆