簡體   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