Plotly - 如何制作无框箱线图?

5
我正在尝试使用Python中的Plotly创建箱线图,但是我只想要点,而不是框线、须线或其他任何内容。类似于这样:enter image description here。我找不到这样做的方法。我最好能做的就是设置boxpoints='all',但那只会显示框线旁边的点:enter image description here。这是否可能?有什么解决办法吗?
1个回答

6

pointpos = 0设置为零,并将要删除的元素的颜色设置为rgba(0,0,0,0)

图表:

enter image description here

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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接