繁体   English   中英

Plotly 子图中的不同箱线图系列痕迹

[英]Different Box Plot Series Traces Within Plotly Subplots

我正在尝试使用 Plotly 创建一系列子图,每个子图都包含箱形图。 目前我已经设法创建了以下情节;

阴谋 .

不幸的是,这并不是我想要的。 我想为 S1 和 S2 而不是 A1 和 A2 创建一个子图(这样每个子图都会有一个绿色箱形图和一个红色箱形图)。

这可能吗?

这是我当前的代码。

x = ['S1', 'S1', 'S1', 'S1', 'S1', 'S1',
     'S2', 'S2', 'S2', 'S2', 'S2', 'S2']

trace0 = go.Box(
    y=[1.935, 2.59, 2.97, 2.97, 3.28, 4.315, 1.935, 2.59, 2.97, 2.97, 3.28, 4.315],
    x=x,
    name='A1',
    marker=dict(
        color='#3D9970'
    )
)
trace1 = go.Box(
    y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
    x=x,
    name='A2',
    marker=dict(
        color='#FF4136'
    )
)
fig = tools.make_subplots(rows=1, cols=2)
fig.append_trace(trace0, 1, 1)
fig.append_trace(trace1, 1, 2)
py.iplot(fig)

我知道答案已经晚了,但是对于目前需要这个的任何人来说,问题是如果你想比较 S1 和 S2,你应该为每个图表使用不同的 X。

`from plotly.subplots import make_subplots
import plotly.graph_objects as go

x = ['S1', 'S1', 'S1', 'S1', 'S1', 'S1',
     'S2', 'S2', 'S2', 'S2', 'S2', 'S2']

trace0 = go.Box(
    y=[1.935, 2.59, 2.97, 2.97, 3.28, 4.315],
    x=[i+'_A1' for i in x[:6]],
    name='S1_A1'
)

trace1 = go.Box(
    y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5],
    x=[i+'_A2' for i in x[:6]],
    name='S1_A2'
)


trace2 = go.Box(
    y=[1.935, 2.59, 2.97, 2.97, 3.28, 4.315],
    x=[i+'_A1' for i in x[6:]],
    name='S2_A1'
)


trace3 = go.Box(
    y=[0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
    x=[i+'_A2' for i in x[6:]],
    name='S2_A2'
)

fig = make_subplots(rows=1, cols=2)

### First subplot ###
# S1_A1
fig.append_trace(trace0, row = 1, col = 1)
# S2_A2
fig.append_trace(trace1, row = 1, col = 1)
#### Second subplot ###
# S1_A1
fig.append_trace(trace2, row = 1, col = 2)
# S2_A2
fig.append_trace(trace3, row = 1, col = 2)

fig.show()´

结果图片

删除了您为使用不同的颜色而获得的颜色

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM