【问题标题】:Plotly - how to make boxplot without boxes?Plotly - 如何制作没有盒子的箱线图?
【发布时间】:2019-08-28 18:26:22
【问题描述】:

我正在尝试在 python 中使用 plotly 来创建箱线图,但我只想要点,而不是框、晶须或其他任何东西。像这样的东西:

找不到这样做的方法。我能做的最好的设置是设置boxpoints='all',但这只会显示除了框的点:

这甚至可能吗?任何解决方法的想法?

【问题讨论】:

    标签: python plotly plotly-python


    【解决方案1】:

    pointpos = 0 和要删除的所需元素的颜色设置为rgba(0,0,0,0)

    剧情:

    Jupyter Notebook 代码:

    # imports
    import plotly
    from plotly import tools
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
    import pandas as pd
    import numpy as np
    import plotly.plotly as py
    import plotly.graph_objs as go
    
    # setup
    init_notebook_mode(connected=True)
    np.random.seed(123)
    
    # data
    y0 = np.random.randn(50)-1
    y1 = np.random.randn(50)+1
    
    # traces
    trace0 = go.Box(
        y=y0, boxpoints = 'all', pointpos = 0,
        marker = dict(color = 'rgb(66, 167, 244)'),
        line = dict(color = 'rgba(0,0,0,0)'),
        fillcolor = 'rgba(0,0,0,0)'
    )
    
    trace1 = go.Box(
        y=y1, boxpoints = 'all', pointpos = 0,
        marker = dict(color = 'rgb(84, 173, 39)'),
        line = dict(color = 'rgba(0,0,0,0)'),
        fillcolor = 'rgba(0,0,0,0)'
    )
    
    # figure
    data = [trace0, trace1]
    layout = go.Layout(width=750, height=500)
    fig = go.Figure(data, layout)
    
    # plot
    iplot(fig)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-03
      • 2020-05-22
      • 2020-12-02
      • 2018-05-10
      • 1970-01-01
      • 2020-02-13
      • 2019-11-15
      • 1970-01-01
      相关资源
      最近更新 更多